Write and run unit tests for your helper functions using Test scripts.
Test scripts let you write unit tests for your helper functions (see Blank Scripts) and run them directly in the Rive editor.
Use them to verify math helpers, string utilities, or any other pure logic your scripts depend on.Beyond validating your code, tests also serve as precise instructions for the AI Agent, helping it produce code that behaves exactly as you intend.
-- Load the script that you want to create tests forlocal MyUtil = require('MyUtil')function setup(test: Tester) local case = test.case local group = test.group -- Create a single case with multiple tests case('Addition', function(expect) local result = MyUtil.add(2, 3) expect(result).is(5) expect(result).greaterThanOrEqual(5) end) -- Organize your tests with groups group('Math', function() case('Subtraction', function(expect) local result = MyUtil.subtract(2, 3) expect(result).is(-1) end) case('Multiplication', function(expect) local result = MyUtil.multiply(2, 3) expect(result).greaterThanOrEqual(6) end) group('Trigonometry', function() case('Degrees to Radians', function(expect) local result = MyUtil.deg2rad(180) expect(result).is(math.pi) end) end) end)end
Tip: Use descriptive names for your groups and cases. They show up in the test results panel and make it easier to see what failed.
You can invert any matcher by chaining .never before it.
This means: the test passes only if the matcher would normally fail.
case('never examples', function(expect) -- This passes because 2 + 2 is NOT 3 expect(2 + 2).never.is(3) -- This passes because 4 is NOT >= 6 expect(4).never.greaterThanOrEqual(6)end)