Kotest Assertion Mode
Assertion Mode controls what happens when a test runs without executing any assertions.
Assertion Mode
When using the Kotest framework with Kotest assertions, you can make the build fail or print a warning to stderr if a test runs without executing any assertions.
To do this, set assertionMode to AssertionMode.Error or AssertionMode.Warn inside the spec.
For example:
import io.kotest.core.spec.style.FunSpec
import io.kotest.core.test.AssertionMode
class MySpec : FunSpec() {
init {
assertions = AssertionMode.Error
test("this test has no assertions") {
val name = "devkuma"
name.length == 7 // this isn't actually testing anything
}
}
}
Running this test prints the following result:
Test 'this test has no assertions' did not invoke any assertions
It can also be configured globally through project configuration or with the system property kotest.framework.assertion.mode.
NOTE
Assertion Mode works only with Kotest assertions and does not work with other assertion libraries.