Kotest アサーションモード(Assertion Mode)
Assertion Mode は、アサーションを実行しないテストが実行された場合の動作を制御するオプションである。
Assertion Mode
Kotest フレームワークと Kotest アサーションを使用している場合、アサーションを実行しないテストが実行されたときに、ビルドを失敗させたり stderr に警告を出力したりできる。
これを行うには、スペック内で assertionMode を AssertionMode.Error または AssertionMode.Warn に設定する。
例:
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
}
}
}
このテストを実行すると、次のような結果が出力される。
Test 'this test has no assertions' did not invoke any assertions
グローバルに設定する場合は、プロジェクト設定またはシステムプロパティ kotest.framework.assertion.mode から設定できる。
NOTE
Assertion Mode は Kotest アサーションにのみ機能し、他のアサーションライブラリには機能しない。