如何使Spock重试失败的Geb测试?

Joh*_*ugh 2 grails groovy spock geb

我有一个使用Geb和Spock的Grails应用程序的功能测试.偶尔,功能测试将因超时或其他偶发行为而失败.在之前使用TestNG的项目中,我有一个retryAnalyzer只是在测试执行期间触发重试,以查看它是否两次都失败(然后真实失败).

如何让Spock重试失败的测试?

小智 8

我知道这个问题已经有一年了,但我们遇到了同样的问题.按照彼得的建议,我创建了一个Spock扩展(https://github.com/anotherchrisberry/spock-retry).

如果您有基本规范(我们的情况),您只需添加一个@RetryOnFailure注释:

@RetryOnFailure
class BaseFunctionalSpec extends Specification {
    //    all tests will execute up to two times before failing
}
Run Code Online (Sandbox Code Playgroud)

或者,您可以将其添加到特定功能:

class SomeSpec extends Specification {

    @RetryOnFailure(times=3)
    void 'test something that fails sporadically'() {
        // will execute test up to three times before failing
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 这是最好的扩展 (2认同)