Why Junit Cases not run in order in JDK 7.


Conclusion first:

Junit uses reflection for getting and executing test methods. Junit get list of all tests using “Method[] getDeclaredMethods()” from java.lang.Class.

The elements in the array returned by getDeclaredMethods are not sorted and are not in any particular order.

How to make executions order fixed

Since JUnit 4.11, you can do:

 public class MyTest {

Reference: MethodSorters
Annotation Type FixMethodOrder