In an ideal world, all your integration/functional tests would run in a deterministic way. In reality, this isn’t always possible. Slow external systems, database bottlenecks, network load, and other undesirable factors can sometimes affect the result of a test (especially if you’ve marked it with the @Timeout annotation) in a semirandom manner.
I’ve worked on projects where a failed build doesn’t mean that the code is broken, but that the network is congested (and rebuilding the code will make all tests pass). For those cases, you can save yourself some time by using the Spock Retry extension (https://github.com/anotherchrisberry/spock-retry). It offers you a special annotation that gives a second chance to your Spock test if it fails, as shown in the next listing.
The annotation can also be used on the class level so that all feature methods gain this capability. By default, the test will be retried twice. You can change this value in the annotation itself, as the following listing shows.
At the time of writing, this Spock extension isn’t yet in Maven Central, so you must either build it yourself or find another repository that contains it.
3.145.71.115