Quick testing tips #12


Test exceptions with Junit5




import io.kotest.core.spec.style.StringSpec
import org.junit.jupiter.api.Assertions.assertThrows

class Test : StringSpec({
  "it should throw exception" {
    val systemUnderTest = SystemUnderTest()
    assertThrows(CustomException::class.java) {
      systemUnderTest.doStuff()
    }
  }
})



Need to check system under test against exceptions? Use assertThrows from Junit5 assertions package.



Read next:


Loading ...
Failed to load data.