kotest-assertions / io.kotest.assertions / shouldFail

shouldFail

inline fun shouldFail(block: () -> Any?): AssertionError

Verifies that block throws an AssertionError

If block throws an AssertionError, this method will pass. Otherwise, it will throw an error, as a failure was expected.

This should be used mainly to check that an assertion fails, for example:

    shouldFail {
       1 shouldBe 2  // This should fail
    }

See Also

shouldThrowAny

shouldThrow

shouldThrowExactly