Spock:PollingConditions 期望最终抛出异常

Spock: PollingConditions expect exception to eventually be thrown

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

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

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

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