11
在Kotlin中测试预期的异常
在Java中,程序员可以为JUnit测试用例指定预期的异常,如下所示: @Test(expected = ArithmeticException.class) public void omg() { int blackHole = 1 / 0; } 我将如何在Kotlin中做到这一点?我尝试了两种语法变体,但没有一个起作用: import org.junit.Test // ... @Test(expected = ArithmeticException) fun omg() Please specify constructor invocation; classifier 'ArithmeticException' does not have a companion object @Test(expected = ArithmeticException.class) fun omg() name expected ^ ^ expected ')'