Spock: RepeatedTest analog in spock 2.0

Created on 4 Mar 2021  路  2Comments  路  Source: spockframework/spock

Spock version: 2.0-groovy-3.0-SNAPSHOT
Problem: need a tool to repeat certain test _regardless_ of the outcome
Junit5 equivalent: @RepeatedTest

I used to have a simple custom 'Rerun' extension for this purpose, but it no longer works in spock 2.0.
my extension for spock 1.3: RerunExtension
error I receive in spock 2.0:

java.util.NoSuchElementException
    at java.util.LinkedList.removeFirst(LinkedList.java:270)
    at org.spockframework.mock.runtime.MockController.leaveScope(MockController.java:76)

which is thrown right after the end of the second run (first repeated run).
Looking at available @Retry, I don't think it's possible to achieve with current implementation since it only retries on throwable thrown.
I unfortunately wasn't able to track down the issue or come up with a workaround, so any help/hint will be greatly appreciated.

Most helpful comment

Do you need this for also for data-driven tests? Otherwise it would be just where: run << (1..10)

And even for data-driven with multi variable data pipes:

where:
[[param1, param2], run] << [[
 ['a', 'b'],
 ['c', 'd']
], (1..5)].combinations()

You could adapt the code from @Retry for the time being, but be aware, that it doesn't generate new UniqueIds on re-execution, and while you can now change the DisplayName properly you might run into complications.

To support this properly, might take some time.
BTW you can't combine @ParameterizedTest with @RepeatedTest on JUnit Jupiter either.

All 2 comments

Do you need this for also for data-driven tests? Otherwise it would be just where: run << (1..10)

And even for data-driven with multi variable data pipes:

where:
[[param1, param2], run] << [[
 ['a', 'b'],
 ['c', 'd']
], (1..5)].combinations()

You could adapt the code from @Retry for the time being, but be aware, that it doesn't generate new UniqueIds on re-execution, and while you can now change the DisplayName properly you might run into complications.

To support this properly, might take some time.
BTW you can't combine @ParameterizedTest with @RepeatedTest on JUnit Jupiter either.

That should do the trick, thx

Was this page helpful?
0 / 5 - 0 ratings