【发布时间】:2021-07-02 15:42:12
【问题描述】:
即使是最简单的情况,我也无法让它工作。
在我的课堂上
public static String fail(somestring) {
throw new RuntimeException()
}
这是我的测试:
@Test
public void "Throws exception"() throws Exception {
given:
MyClass test = new MyClass()
when:
test.fail("sdlkfjlsdkfj")
then:
thrown(RuntimeException)
// also tried this
//throw new RuntimeException()
}
我的它只是抛出一个接受并且测试失败。似乎 throw 被忽略了。
【问题讨论】:
-
我认为您混淆了 JUnit 和 Spock。您使用的注释来自 JUnit。您另一个问题中的基类来自 Jenkins,它使用 JUnit。只需在 groovy(甚至 Java AFAIR)中添加
when:或类似的东西,就只是生成一个标签并且是有效代码——如果你不打算“转到”它,那就是无操作。所以这基本上是stackoverflow.com/questions/25519736/… 的复制品,带有额外的误导层。