kiri-check is a property-based testing library for Dart.
- Integrated with package:test, it can be used in the same way as regular tests. Additionally, property-based tests can be added without modifying existing test code.
- Customization of the exploration method is easy. You can specify data ranges, increase or decrease the number of trials, and prioritize edge cases.
Install the library from pub.dev using the following command:
With Dart:
dart pub add dev:kiri_check
With Flutter:
flutter pub add dev:kiri_check
Alternatively, add the library to your pubspec.yaml
and run dart pub get
or flutter pub get
.
dev_dependencies:
kiri_check: ^1.0.0
Please refer to the Documentation.
Properties can be implemented as tests using package:test
. Assertions use functions from package:test
.
- Import the
kiri-check
library.import 'package:kiri_check/kiri_check.dart';
- Implement properties using the
property
function. This function takes the title of the test and the function to execute the test as arguments. - Implement the test to validate test data using the
forAll
function. This function takes an arbitrary that generates random test data as an argument.
Example:
import 'package:kiri_check/kiri_check.dart';
dynamic fizzbuzz(int n) {
// Implement me!
}
void main() {
property('FizzBuzz', () {
forAll(
integer(min: 0, max: 100),
(n) {
final result = fizzbuzz(n);
if (n % 15 == 0) {
expect(result, 'FizzBuzz');
} else if (n % 3 == 0) {
expect(result, 'Fizz');
} else if (n % 5 == 0) {
expect(result, 'Buzz');
} else {
expect(result, n.toString());
}
},
);
});
}
- Stateful tests
- Optimize random number generation
- Web support
Apache License, Version 2.0