验证 Spock 中没有抛出异常

Verify no exceptions were thrown in Spock

我是 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
    }
}

关于如何实现这个的任何想法?

找到了。

您可以使用

noExceptionThrown()

断言没有抛出任何东西