【发布时间】:2015-11-14 14:38:19
【问题描述】:
我是 Spock 的新手,我仔细阅读了他们的在线文档。我有一个测试用例,我需要验证我的夹具与非模拟协作者的交互是否不产生异常:
class FizzSpec extends Specification {
def "no exception thrown when we hail buzz"() {
given:
Fizz fixture = new Fizz()
Buzz buzz = new Buzz("YES", true, "Garble barb") // A non-mock!
when:
fixture.hail(buzz)
// TODO: How to verify the hail didn't produce an exception?
// then:
// thrown() == null
}
}
关于如何实现这一点的任何想法?
【问题讨论】:
-
如果知道异常类型可以
notThrown(NullPointerException)