【发布时间】:2015-07-31 15:30:18
【问题描述】:
在 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 ')'
【问题讨论】:
标签: unit-testing kotlin testing exception junit4