junit5 icon indicating copy to clipboard operation
junit5 copied to clipboard

Allow @RepeatedTest to stop upon failure

Open jaikiran opened this issue 5 years ago • 9 comments

Many a times when a particular test is a failing once in a while (i.e. not consistently), I use the @org.junit.jupiter.api.RepeatedTest with a relatively high number like 10:

@RepeatedTest(10)

and trigger the tests to try and reproduce the issue. Some of these 10 runs will fail (as expected). However, the only reason I used the @RepeatedTest was to reproduce a failure and once that failure has occurred, I'm not really interested in running the remaining number of "count" that was passed to it.

Would it be a good idea to introduce something like stopOnFailure attribute (which can be set to true, but defaults to false) to this @RepeatedTest so that it considers the value count as the maximum number of times to run the test and if stopOnFailure is set to true then stops as soon as the first run within those 10 runs fails?

jaikiran avatar Dec 03 '19 01:12 jaikiran

Tentatively slated for 5.6 M2 solely for the purpose of team discussion

juliette-derancourt avatar Dec 03 '19 08:12 juliette-derancourt

Team decision: Wait for additional interest from the community.

marcphilipp avatar Dec 05 '19 11:12 marcphilipp

@marcphilipp can I pick this up?

antimpatel avatar Dec 12 '19 13:12 antimpatel

@antimpatel Please note that we haven't taken a decision whether we want to add and maintain this functionality. However, it would certainly help to see it spelled out in a spike. I think one of the main complications will be to change the execution mode to same_thread if the feature is used. You'll probably have to add a getExecutionMode() method or sth. similar to TestTemplateInvocationContextProvider.

marcphilipp avatar Dec 17 '19 13:12 marcphilipp

I like this idea. The option to stop on failure could help test runs terminate quicker if there are faults.

ghost avatar Dec 21 '19 03:12 ghost

really useful, we also have such huge integration tests failing sporadically and needing 20 repetitions to prove that there is no problem, but after the first failure there is no need to run the remaining repetitions. My suggestion is: adding the number of failures to RepetitionInfo and let the test decide if it needs more repetitions.

qeepcologne avatar Dec 03 '20 10:12 qeepcologne

JUnit Pioneer has the opposite: @RetryingTest stops upon the first success.

@qeepcologne Would you like to bring up the issue there?

marcphilipp avatar Dec 04 '20 11:12 marcphilipp

@marcphilipp I'd like to try this. May I?

YuanPeiqi avatar Apr 23 '22 11:04 YuanPeiqi

Currently repeated test can be represented as individual tests. However failing early changes the semantics significantly. This introduces the concept of an "attempt" which is effectively a sub-test entity.

This has provided some unresolved conceptual difficulty in Cucumber and is likely to do so for JUnit 5. I've written more about it here: https://github.com/junit-team/junit5/issues/2925#issuecomment-1137837182.

mpkorstanje avatar May 25 '22 21:05 mpkorstanje

This would be really useful to have!

We have CI runners of many different shapes and sizes, and for types of tests we need to repeat a test a certain amount of times to trigger a failure. For some runners, fewer repetitions are needed and for others, a lot more repetitions are needed. Stopping on the first failure means we could set a high repetition count without penalizing all CI runs (and runs in local development environments).

slovdahl avatar Mar 10 '23 08:03 slovdahl

Superseded by

  • #2925

sbrannen avatar Apr 13 '23 13:04 sbrannen