Forcing Eclipse to run JUnit tests in the same order that Maven runs them

1.1k views Asked by At

I’m using Maven 3.2.3, SureFire 2.17, JUnit 4.11 and Eclipse Juno on Mac 10.9.5. I notice that when I run my JUnit tests via the command line

mvn test -Dtest=MyTest

the individual tests within the file “MyTest.java” run in a different order than when I run them in Eclipse (by right clicking the class name and selecting “Run As -> JUnit Test”). How do I get Eclipse to run the tests in the same order in which they are run on the command line?

Thanks, - Dave

1

There are 1 answers

0
SmoothD On

The order of JUnit test runs are not guaranteed by design, as is mentioned in the JUnit FAQ page.This is done to promote the concept of test Independence, this will make sure that the tests will test their cases clearly and independently, and also ease maintainability.

This means that when you are running the tests in Eclipse, the orders are not guaranteed and keep changing. It's explained in "Can I change JUnit execution order?" on how you can possibly fix the order, even though its not a good practice.