Before Kotest 5.0, you could apply a default test config to set some properties, like if the tests are enabled or what the timeout is.
Kotest 4
class DbTests : StringSpec() {
override val defaultTestCaseConfig: TestCaseConfig = TestCaseConfig(enabled = !IS_CI, timeout = 24.hours)
init {
"test1" { ... }
"test2" { ... }
}
}
However, since Kotest 5, the defaultTestCaseConfig
syntax has been deprecated https://kotest.io/docs/blog/release_5.0/#default-test-case-config (thankfully, just as a warning for now) with DSL-like syntax in the init
block replacing it. But that syntax seems to lack the enabled
field, which I was using to switch all test in a spec on/off at the same time. I can still apply the condition on a test-by-test basis, but that is duplicate code and what if you forget one?
Kotest 5
class DbTests : StringSpec() {
override fun defaultTestCaseConfig(): TestCaseConfig = TestCaseConfig(enabled = !IS_CI, timeout = 24.hours) // deprecated
init {
timeout = 24.hours
//enabled - no field to add
"test1".config(enabled = !IS_CI) { ... } // duplicate code
"test2".config(enabled = !IS_CI) { ... }
}
}
Is there a full replacement for defaultTestCaseConfig.enabled
in Kotest 5? That means it should enable/disable all tests in a spec according to a Boolean variable and be specified in a single place, not if the config
block of every test.