Kotest Other Settings

This page explains how to fail fast in Kotest, how to fail on an empty test suite, and other settings.

Fail Fast

Kotest can fail a list of tests quickly when one of the tests fails. This is called Fail Fast.

Fail fast can be applied at the spec level or at the parent test level.

In the following example, fail fast is enabled for the parent test, and when the first failure occurs within that context, the rest are skipped.

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
         }
      }
   }
}

This feature can be enabled for all scopes in a spec by setting fail fast at the spec level.

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
         }
      }
   }
}

Failing on an Empty Test Suite

If you want a project to always run at least one test, enable failOnEmptyTestSuite in project configuration.

If this option is set to true and no tests are executed in the module, the build fails.

class ProjectConfig : AbstractProjectConfig() {
  override val failOnEmptyTestSuite = true
}

Config Dump

Kotest can optionally print the configuration used for test execution when the test engine starts. To do this, set the system property or environment variable named kotest.framework.dump.config to true.

test {
  systemProperty "kotest.framework.dump.config", "true"
}

For example, when using Gradle, set the system property inside the test task configuration block.

~~~ 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

References