kotest-extensions / io.kotest.extensions.system / SpecSystemExitListener

SpecSystemExitListener

object SpecSystemExitListener : TestListener

Will replace the SecurityManager used by the Java runtime with a NoExitSecurityManager that will throw an exception if System.exit() is invoked. This exception can then be tested for with shouldThrow().

After the spec has completed, the original security manager will be set.

To use this, override listeners() in your Spec class.

Note: This listener is only suitable for use if parallelism is set to 1 (the default) otherwise a race condition could occur.

If you want to change the security manager for the entire project, then use the alternative SystemExitListener

Functions

afterSpec

suspend fun afterSpec(spec: Spec): Unit

beforeSpec

suspend fun beforeSpec(spec: Spec): Unit