【问题标题】:Verify no exceptions were thrown in Spock验证 Spock 中没有抛出异常
【发布时间】: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)

标签: groovy spock


【解决方案1】:

找到了。

你可以使用

noExceptionThrown()

断言没有抛出任何东西

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-06-29
  • 2015-07-10
  • 2014-05-10
  • 2013-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多