kiri-check Help

Generation

Generation policy

The Generation policy (GenerationPolicy) determines the tendencies in the data generated by arbitraries. Data generation by arbitraries is not purely random; the distribution of data is adjusted to enable more efficient testing. GenerationPolicy can be specified through the generationPolicy in forAll.

The policies available are as follows:

  • GenerationPolicy.auto: The default behavior, which tries to cover the range of values that can be generated by the arbitrary. Subsequent behavior depends on the implementation of the arbitrary.

  • GenerationPolicy.exhaustive: The arbitrary covers the entire possible range of values it can generate. Refer to the "Exhaustive generation" section for more details.

  • GenerationPolicy.random: Generates completely random data.

Regardless of the chosen policy, the same set of data is consistently generated at the beginning of each test execution, ensuring the reproducibility of tests.

Generate edge cases

The generation of edge cases can be explicitly specified. Specify EdgeCasePolicy in the edgeCasePolicy of forAll. The policies available are:

  • EdgeCasePolicy.none: Does not generate edge cases.

  • EdgeCasePolicy.mixin: The default behavior. Generates edge cases randomly or at a certain ratio.

  • EdgeCasePolicy.first: Generates edge cases first.

Edge cases vary by arbitrary. Generally, minimum values, maximum values, and special values are generated as edge cases.

Generate enums

While there is no dedicated arbitrary for Enum, using constantFrom allows you to cover enum values.

enum Color { red, green, blue } property('enum', () { forAll( constantFrom(Color.values), (value) { expect(value, isIn(Color.values)); }, ); });

Exhaustive generation

Some arbitraries can cover all possible values they are capable of generating. To generate all values, specify GenerationPolicy.exhaustive. When this policy is set, the arbitrary prioritizes the generation of all possible values.

Specifying this policy with arbitraries that do not support exhaustive generation will result in an error.

Consistent generation

To always generate the same data, fix the random seed. Refer also to Fix random seed.

Last modified: 13 September 2024