Test expected exceptions in Kotlin

后端 未结 11 782
我寻月下人不归
我寻月下人不归 2021-02-02 04:45

In Java, the programmer can specify expected exceptions for JUnit test cases like this:

@Test(expected = ArithmeticException.class)
public void omg()
{
    int bl         


        
11条回答
  •  醉话见心
    2021-02-02 05:28

    org.junit.jupiter.api.Assertions.kt

    /**
     * Example usage:
     * ```kotlin
     * val exception = assertThrows("Should throw an Exception") {
     *     throw IllegalArgumentException("Talk to a duck")
     * }
     * assertEquals("Talk to a duck", exception.message)
     * ```
     * @see Assertions.assertThrows
     */
    inline fun  assertThrows(message: String, noinline executable: () -> Unit): T =
            assertThrows({ message }, executable)
    

提交回复
热议问题