I am still looking for a solution to retry tests which fit all my requirements #781
Replies: 3 comments 1 reply
-
First and foremost, JUnit is a unit test library, which makes retrying tests an anti-pattern. If you know the FIRST acronym, it means unit tests are supposed to be reliable (or, alternatively, repeatable), meaning they should always run exactly the same way and give the same result (for the same build). If you have to introduce retry logic, that means your test is either not reliable or not a unit test. But hey, what if it is not a unit test? The idea of having to retry test is a bit less clear in this case, but it could be pointing to underlying problems in the code that you are testing.
These examples don't mean that you should 100% never ever retry your tests. Sometimes retrying your tests is the best solution or it is simply unavoidable. But this is the edge-case, meaning there is not a lot of demand for a retry mechanic. When there is demand, it's usually covered by what Pioneer does - just slap the annotation on your test and you are good to go: your test will run again if it failed (up to a certain number of retries). Would these people benefit from a more robust retrying extension? Almost certainly, but for most use-cases I think simply having a way to restart a test is "good enough". Another thing you have to consider is that your example There are other, more practical reasons why this is not in Pioneer. One of it is the way we register and parameterize extensions, mainly annotations. The more input a certain extension needs, the more property the annotation has. It goes without saying that after a certain number this just looks bad:
I hate just even looking at something like this, to be quite honest. 😕 Okay, it could also look a bit more reasonable:
But this is still a lot. We would need a way to parameterize the extension without all this clutter. Which could look like this:
This is an okay solution - but it's a mindset shift from how the extension is currently set up. But ultimately, the simple reason we don't have something like this is because no one thought about it. I believe you are a first person who wants to have something like this in Pioneer. |
Beta Was this translation helpful? Give feedback.
-
Hey you 👋,
|
Beta Was this translation helpful? Give feedback.
-
Sorry for the late reply. When a retry is done then the produced XML should look like below: <testcase name=".." classname=".." time="0.1">
<flakyFailure message="exception message" type="assertion exception">
<stackTrace>flaky failure stack trace</stackTrace>
<system-out> flaky failure System.out log message </system-out>
</flakyFailure>
<system-out> success </system-out>
</testcase> This is what JUnit calls the legacy XML format. But many tools support this convention to identify flaky tests, for example the Allure report. JUnit advocates for a new test reporting format, but it obviously does not support to contain information about retries. So I asked on their Github project about it now: ota4j-team/open-test-reporting#62 I understand that you do not want to be dragged into creating/maintaining a test report. Now I have your extension for retrying and also implemented to use Failsafe for the same purpose, side by side for a while to see which one to keep. My impression until now is that using Failsafe is overall better for me. Retries are not so transparent with Failsafe in the Allure test report, but the number of tests is correct and I can do more with its RetryPolicy. I am not sure what you meant with your idea, ordering tests is not really possible for me because I do want to run them in full parallel mode. Currently I am not sure if there is a perfect solution at all regarding the test report side of things. Maybe if the open-test-reporting Github project will support retries then there can be a chance to craft a good solution for the future. |
Beta Was this translation helpful? Give feedback.
-
I did not find any good retry solution for JUnit 5 tests, no offense intended.
Maybe I have high expectations. When automating E2E tests in a professional way then you need certain features for retries and not only the bare minimum. For retrying certain steps or group of steps there is a great Java library called Failsafe. It has everything I need and more.
But when I need to repeat a whole test I did find only half-baked solutions.
What do I need? Basically all what can be done with Failsafe's retry policy, including, maximum number of retries, a delay between retries, supporting a jitter factor, backoffs and being able to handle specific exceptions only. A retry policy should be configurable per test and should not have to be a general one for all the tests in an execution. Beyond that it should be possible to set a maximum total number of retries for all the tests combined. It should output flaky re-run information in test report XML so that they can be properly displayed in tools like Allure Report. Ideally it would also be possible to specify if a test is considered as failed if it needed to be retried.
None of the tools I know fit to these requirements, neither Maven Surefire plugin, nor test-retry-gradle-plugin for Gradle. Also junit-pioneer does not support many of these requirements, for instance in the Allure report the retried tests are counted as ignored tests and not identified as retried tests, because the report XML does not output re-run information but marks retryed tests as disabled.
So while I am super happy with Failsafe for retrying test steps, I did not find anything of that quality for retrying tests itself. Again, no offense, it is just how it is. Obviously no one created a solution for all the requirements I mentioned.
But why not? Is it not possible? Or not many have such high expectations like me for it? Or why?
Beta Was this translation helpful? Give feedback.
All reactions