Property-based testing library for Kotlin.
Main features:
- Test-engine agnostic
- Multiplatform
- No reflection
- Configurable built-in generators
- Easy way to create and combine generators
- Seeded generation for reproducible results
Find more information on https://kwik.readthedocs.io
This project is discontinued. For property based testing with Kotlin, check out kotest.
class PlusOperatorTest {
@Test
fun isCommutative() = forAll { x: Int, y: Int ->
x + y == y + x
}
@Test
fun isAssociative() = forAll(iterations = 1000) { x: Int, y: Int, z: Int ->
(x + y) + z == x + (y + z)
}
@Test
fun zeroIsNeutral() = forAll(seed = -4567) { x: Int ->
x + 0 == x
}
}
For more information read the usage and look at the available generators
Property based testing is great and very powerful. But despite the fact that many good libraries already exist, none of them fully fit my needs.
The known alternatives either:
- Are bound to a specific test-engine
- Can only be used when compiling kotlin to Java (and cannot be used in multi-platform projects)
- Relies on reflection, making the tests slower and make some errors detectable only at runtime
- Do not allow enough freedom and safety to customize existing generators
- Force the user to add unwanted dependencies in the classpath
- Kotlin version: 1.4.0 or newer
- JDK version: 8, 11 or 15
Example of setup using gradle.
repositories {
jcenter()
}
dependencies {
testCompile("com.github.jcornaz.kwik:kwik-core-jvm:$kwikVersion")
}
Find more detailed information in the setup instructions.