在 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 ')'