Quickstart
Set up
Create a new project
There is no need for a special project structure to introduce kiri-check. Simply create a regular project using the dart
command (or flutter
command).
Install
Install the library from pub.dev using the following command:
With Dart:
With Flutter:
Alternatively, add the library to your pubspec.yaml
and run dart pub get
or flutter pub get
.
Write a simple property
Writing a property is straightforward. kiri-check is integrated with package:test
and can be used alongside it. There is no need to change existing unit test code; you can simply add properties.
Let’s write a very simple property. Create a file named simple_test.dart
in the test
directory and add the following code:
simple_test.dart
:
This property uses the integer
arbitrary to generate a random integer and verifies that the integer is of type int
. This property will always succeed (provided there are no bugs in kiri-check).
Properties are defined with the property
function. property
accepts the same arguments as the test
function from package:test
. The forAll
function used within the block passed to property
takes an arbitrary that generates random values and a block that receives these values. In that block, you can verify the values using the expect
function from unit tests.
Run the test
Running the test is the same as with package:test
. Execute it with the dart test
command.
If a property fails, shrinking will occur to display the smallest value that causes the error.
Where to next?
Whether you are familiar with property-based testing or not, it's a good idea to look through the list of arbitraries to get to know the main ones. If you're new to property-based testing, reading a book on the subject is also a good idea. Though it's intended for Erlang and Elixir, I recommend Property-Based Testing with PropEr, Erlang, and Elixir: Find Bugs Before Your Users Do (Japanese translation).