Spock:PollingConditions期望最终抛出异常

时间:2017-06-23 19:24:33

标签: groovy spock

我正在尝试使用PollingConditions来期望最终会抛出异常。

then:
 new PollingConditions(timeout: 3, initialDelay: 0.1, delay: 0.1).eventually {
  sasClient.getSASToken(pod, targetServiceType)
  thrown(NotFoundException)
 }

但这会导致Groovy抱怨:Groovyc: Exception conditions are only allowed as top-level statements

是否可以测试最终会抛出异常?

1 个答案:

答案 0 :(得分:1)

也许GroovyAssert可以帮助你,试试这个:

new PollingConditions(timeout: 3, initialDelay: 0.1, delay: 0.1).eventually {
  GroovyAssert.shouldFail(NotFoundException) {
    sasClient.getSASToken(pod, targetServiceType)
  }
}