kotest-core / io.kotest.core.spec.style / AnnotationSpec / Test

Test

annotation class Test

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
}

Types

None

object None : Throwable

Constructors

<init>

Marks a function to be executed as a Test

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

Properties

expected

val expected: KClass<out Throwable>