kotest-core / io.kotest.core.spec.style / AnnotationSpec / Test / <init>

<init>

Test(expected: KClass<out Throwable> = None::class)

Marks a function to be executed as a Test

This can be used in AnnotationSpec to mark a function to be executed as a test by Kotest Engine.

expected can be used to mark a test to expect a specific exception.

This is useful when moving from JUnit, in which you use expected to verify for an exception.

@Test(expected = FooException::class)
fun foo() {
  throw FooException()  // Pass
}

@Test(expected = FooException::class
fun bar() {
  throw BarException() // Fails, FooException was expected
}