2

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

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Dave A
  • 2,780
  • 9
  • 41
  • 60
  • 3
    If the order in which your tests run affects the outcome, it suggests that you have dependencies between tests, which is a code smell. If this is the case, refactoring is advisable. – Asaph Nov 20 '14 at 22:01
  • I appreciate your advice. But that wasn't my question. – Dave A Nov 20 '14 at 22:14
  • Why do you care in what order the tests run? – Asaph Nov 20 '14 at 22:40
  • https://github.com/junit-team/junit/blob/master/doc/ReleaseNotes4.11.md#test-execution-order – Asaph Nov 20 '14 at 22:43
  • possible duplicate of [Ordering unit tests in Eclipse's JUnit view](http://stackoverflow.com/questions/512778/ordering-unit-tests-in-eclipses-junit-view) – Joe Nov 22 '14 at 01:03

1 Answers1

1

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.

Community
  • 1
  • 1
SmoothD
  • 11
  • 1