Description
When a test is annoated with @TestMethodOrder( MethodOrderer.OrderAnnotation.class )
we want the test methods to executed in the order of the @Order
annotation.
When twei methods have the same order value the Javadoc states they "will be sortedarbitrarily adjacent to each other". That makes perfect sense.
Imagine this scenario: We have a tets class which contains 6 steps - each of them depends on its predecessor. Each of them is annotated by @Order
with an incremented number. Later on we add step between 2 and 3 and accidently copy the @Order
annotation from another method.
This might lead to a flaky test as the same order value is used twice.
For sure this is the developer's mistake, but what about defining that each test method has to have an unique order value as we want to control the execution order deterministically?
We could have a special MethodOrderer for this purpose like
@TestMethodOrder( MethodOrderer.EnforcingOrderAnnotation.class )
The whole test class failes if there are at least two methods with the same order value.