验证Spock中没有抛出任何异常

sme*_*eeb 23 groovy spock

我是Spock的新手,并仔细阅读他们的在线文档.我有一个测试用例,我需要验证我的fixture与非模拟协作者的交互不会产生异常:

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
    }
}
Run Code Online (Sandbox Code Playgroud)

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

tim*_*tes 46

找到了.

您可以使用

noExceptionThrown()
Run Code Online (Sandbox Code Playgroud)

断言没有抛出任何东西