I'd like to limit the default number of iterations for Property Based Tests in Kotest, preferably in the code (instead of using the also existing system property kotest.proptest.default.iteration.count
inside my gradle/maven project).
The Global Configuration | Kotest Property Testing page states that I can achieve this by setting PropertyTesting.defaultIterationCount
to some value. What I don't get is where to place this assignment. The documentation for Project Wide Configuration in the Framework says I have to override AbstractProjectConfig
, which sadly does not include any properties regarding PBT.
The following code works by invoking the assignemnt as a side effect:
import io.kotest.core.config.AbstractProjectConfig
import io.kotest.property.PropertyTesting
class TestConfig : AbstractProjectConfig() {
init {
PropertyTesting.defaultIterationCount = 123
}
}
is there a better way configuring PBT?
The global configuration for Property Testing in Kotest is not tied to Kotest framework itself, because you can use the prop testing modules from JUnit or anything.
So the way to make this work is to set
PropertyTesting.defaultIterationCount
in some kind of "before project" listener. Now if you're using Kotest framework, it's easy and you're almost there. Just put the assignment inside a beforeProject listener, and it'll be guaranteed to run before any tests.