Kotestその他の設定(Other settings)
Kotestで早期失敗する方法、空のテストスイートの場合に失敗させる方法などについて説明する。
早期失敗
Kotestは、テストの1つが失敗した場合にテスト一覧をすばやく失敗させることができる。これを早期失敗(Fail Fast)という。
早期失敗はSpecレベルまたは親テストレベルで適用できる。
次の例では、親テストに対して早期失敗機能を有効化し、そのコンテキスト内で最初の失敗が発生すると残りはスキップされる。
class FailFastTests() : FunSpec() {
init {
context("context with fail fast enabled").config(failfast = true) {
test("a") {} // pass
test("b") { error("boom") } // fail
test("c") {} // skipped
context("d") { // skipped
test("e") {} // skipped
}
}
}
}
この機能は、Specレベルでfailfastを設定することで、Specのすべてのスコープに対して有効化できる。
class FailFastTests() : FunSpec() {
init {
failfast = true
context("context with fail fast enabled at the spec level") {
test("a") {} // pass
test("b") { error("boom") } // fail
test("c") {} // skipped
context("d") { // skipped
test("e") {} // skipped
}
}
}
}
空のテストスイートで失敗する
プロジェクトが常に1つ以上のテストを実行するようにしたい場合は、プロジェクト構成でfailOnEmptyTestSuiteを有効化すればよい。
このオプションをtrueに設定し、モジュールで実行されたテストがない場合、ビルドは失敗する。
class ProjectConfig : AbstractProjectConfig() {
override val failOnEmptyTestSuite = true
}
TIP
テストが定義されているかどうかに関係なく、テストが実行されなければモジュールは空と見なされる。これは、環境固有の設定などによってテストが誤ってフィルタリングされるシナリオを検出するのに役立つ。
Config Dump
Kotestは、テストエンジンが開始されるときにテスト実行に使用される構成を任意で出力できる。これを行うには、システムプロパティまたは環境変数を設定し、名前をkotest.framework.dump.config、値をtrueに設定する。
test {
systemProperty "kotest.framework.dump.config", "true"
}
たとえばGradleを使用する場合、testタスクの構成ブロック内でシステムプロパティを設定する。
~~~ Kotest Configuration ~~~
-> Parallelization factor: 1
-> Concurrent specs: null
-> Global concurrent tests: 1
-> Dispatcher affinity: true
-> Coroutine debug probe: false
-> Spec execution order: Lexicographic
-> Default test execution order: Sequential
-> Default test timeout: 600000ms
-> Default test invocation timeout: 600000ms
-> Default isolation mode: SingleInstance
-> Global soft assertions: false
-> Write spec failure file: false
-> Fail on ignored tests: false
-> Fail on empty test suite: false
-> Duplicate test name mode: Warn
-> Remove test name whitespace: false
-> Append tags to test names: false
-> Extensions
- io.kotest.engine.extensions.SystemPropertyTagExtension