Spock: PollingConditions期望异常最终会被抛出

3

我正在尝试使用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个回答

3
也许GroovyAssert可以帮助你,试试这个:
new PollingConditions(timeout: 3, initialDelay: 0.1, delay: 0.1).eventually {
  GroovyAssert.shouldFail(NotFoundException) {
    sasClient.getSASToken(pod, targetServiceType)
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接