KuickCheck is a property based testing framework for Kotlin inspired by other property based testing frameworks, especially scalacheck, junit-quickcheck.KuickCheck has no external dependencies other than Kotlin runtime and Kotlin reflection.
KuickCheck is published to Maven Central, so you can get the latest version by adding the dependency to pom.xml or build.gradle.
Currently KuickCheck is not published, so download or clone this project to your machine.
<dependency>
<groupId>org.mikeneck</groupId>
<artifactId>kuickcheck</artifactId>
</dependency>dependencies {
testCompile 'org.mikeneck:kuickcheck'
}Writing test is very easy.
-
Create class or singleton object.
-
Prepare your test data with
Generator(in the sample code it will be prepared bypositiveIntphrase) and pass it toforAllmethod. -
Write the property for the data at
satisfyblock. -
Give the name to the property as read-only field name.
-
Annotate the property with
@Property.
Then KuickCheck will run check for the property 100 times as default.
object GettingStarted {
@Property
val positiveNumberIsMoreThan0 =
forAll(positiveInt).satisfy{ it > 0 }
}KuickCheck jar contains main function at org.mikeneck.kuickcheck.KuickCheck class.
So you can run tests via java -jar command.
Add a new task to run KuickCheck test by JavaExec task.
task runTest(type: JavaExec) {
classpath sourceSets.test.runtimeClasspath
main = 'org.mikeneck.kuickcheck.KuickCheck'
standardOutput = System.out
}