Original link: Test execution order
Original date: December 06, 2012 This
Date: July 2, 2014
Translators: Anchor
Description: Junit4.11 version number and later support, it is recommended to upgrade to the latest version number.
In accordance with the design principle, JUnit does not specify the order in which the test method calls run.
For now, these methods simply run in the order returned by the reflection (reflection) API.
However, it is very unwise to use the default ordering provided by the JVM, since the Java platform is not specified in any regular order.
In fact, JDK 7 may return a random order.
Of course, there is no need to assume that no matter what the order of operation is between well-written test code, but sometimes a predictable failure on some platforms is better than a random failure.
Starting with the 4.11 version, JUnit will default to a deterministic, but not pre-measured order ( Methodsorters.default ).
To change the order of the test run, you only need to use @FixMethodOrder annotations on the test class (Class) and specify an available Methodsorter to:
@FixMethodOrder (METHODSORTERS.JVM) : preserves the order in which the test methods are run in the order that the JVM returns.
The order in which each test is run can be different.
@FixMethodOrder (methodsorters.name_ascending) : Sorts according to the method name of the test method, according to the dictionary control (ASC, small to large, increment).
JUNIT Specifies the test run order