RepeatFailedTest causes sporadically PreconditionViolationException
See original GitHub issueA failed test repeated through @RepeatFailedTest
sporadically leads to:
org.junit.platform.commons.PreconditionViolationException: Illegal state: required test method is not present in the current ExtensionContext
Link to a failed build: https://travis-ci.org/github/spring-projects/spring-data-mongodb/jobs/678085125
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:14 (12 by maintainers)
Top Results From Across the Web
JUnit5: How to repeat failed test? - Stack Overflow
This will rerun each failed test a certain number of times, with the option of failing the build if too many failures have...
Read more >JUnit5 test are not able to run in Eclipse #1007 - GitHub
Select a JUnit execution and ensure that the JUnit5 runner is selected: Click the Run button. The following error is shown: a...
Read more >JUnit 5 User Guide
Used to fail a test, test factory, test template, or lifecycle method if its execution exceeds a given duration.
Read more >تويتر \ Nicolai Parlog 🕊️ على تويتر: " We just released ...
A failed test repeated through @RepeatFailedTest sporadically leads to: org.junit.platform.commons.PreconditionViolationException: Illegal state: required ...
Read more >JUnit 5 How to Repeat Failed Test - Software Test Academy
Rerun failed tests is important in test automation projects. In this tutorial, I will explain to you how to repeat JUnit 5 tests...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What’s going on?
The
@RepeatFailedTest
extension is mainly a test template, which means it becomes it’s own container for the tests it generates and doesn’t need an additional@Test
annotation (just like@ParameterizedTest
).In the linked example, the test method is annotated with
@Test
and@RepeatFailedTest
, though, just like this example:This means if the test is successful, it’s executed twice:
If it isn’t successful, things get a bit more complicated. I said, this is extension is mainly a test template. It’s also a
TestExecutionExceptionHandler
, so it can catch exceptions and trigger an additional run:Note the lengthy comment (ha!), which explains why we go from the failed test’s context to its parent (in
handleTestExecutionException
) to access the store (inrepeaterFor
). The implicit assumption is thathandleTestExecutionException
is called for a failed test that was generated from the annotated method (hence “go to parent!” ~> “get store”).Now, if the method is also annotated with
@Test
and it fails, this assumption is invalid: The extension is still aTestExecutionExceptionHandler
and thus is called to handle that failed test, but since that test is the method itself (not a generated test), it’s parent is a test class (not the test method) and thusgetRequiredTestMethod
inrepeaterFor
fails with the observedPreconditionViolationException
.What can the user do?
Remove
@Test
. This is not optional because even if the extension would detect this case and rethrow the exception, the@Test
-test would fail and thus break the build (regardless of what the@RepeatFailedTest
-tests do).What can we do?
Two things come to mind:
@Test
is not neededNo strong opinion on naming. It probably doesn’t make sense to rename and cause downstream effort as current proposal are mostly different but not significant more comprehensive.