kiri-check Help

Write properties

Tests in kiri-check are written within the framework of package:test. Each test consists of two main components. The first is the property function, which sets up the test, and the second is the forAll function, which receives the generated values and executes the test block. The test execution block is encapsulated within forAll and property.

property is a wrapper for test and accepts the same arguments. forAll takes an arbitrary and a block, passing the values generated by the arbitrary to the block's arguments. The block is executed as many times as values are generated. Within the block, values are verified using the expect function, just like in regular tests.

property('generate integers', () { forAll(integer(min: 0, max: 100), (value) { expect(value, greaterThanOrEqualTo(0)); expect(value, lessThanOrEqualTo(100)); }); });

Using multiple forAll within one property, or nesting forAll, does not guarantee behavior. If you need to use multiple arbitraries or choose arbitraries based on conditions, you should use a composite arbitrary. See Composition for more details.

Be aware that neither property nor forAll execute immediately. Processes dependent on the start or end of property or forAll should not be written outside the test block. See Set up and tear down as well.

Run tests

Tests are run with the dart test command, just like with package:test. If a test fails, shrinking is performed and the smallest found value is displayed as part of the error message.

If you want to know the generated and shrunk values, specify Verbosity.verbose in KiriCheck.verbosity.

Set up and tear down

Set up and tear down processes are passed as callbacks in the arguments of forAll. Set up is specified with setUp, and tear down with tearDown.

Integrate with package:test

kiri-check can coexist with package:test. There is no need to alter existing test code using package:test, and the reverse is also true.

Last modified: 13 September 2024