0

I'm working with JUnit. I create a Request object that receives a list of classes that have tests.

When I execute a sorter on Request and then run it, it appears the tests are sorted but only contrary to the class in which they originally where!

Example:

Class 1 with test A,D,C and Class 2 with test A,I,H Given to the request, sorted alpabetically execute in this order:

Test A, Test C, Test D, Test A, Test H, Test I

instead of AACDHI.

Sven
  • 1,133
  • 1
  • 11
  • 22

1 Answers1

0

Writing dependent test is a very bad practice. Each test unit is independent and must be performed independently. This is the main objective of unit testing. Test will check only one simple part of the system and never all together.

If you need guaranteed perform each step, you should write tests as a simple methods and combine into one big test.

You may have a different opinion, but I'm doing it so.

Also, it has been discussed - How to run test methods in specific order in JUnit4?

Community
  • 1
  • 1
MartenCatcher
  • 2,713
  • 8
  • 26
  • 39
  • I am developping an application on top of Junit, one of the features is that you can return the tests in alpabetical order, execute tests in the order in which they failed the previous test run, etc. The tests aren't mine, so the above link don't work. – Sven Nov 19 '13 at 18:02
  • You can use an own default runner: http://junit.org/javadoc/latest/org/junit/runner/Runner.html – Stefan Birkner Nov 19 '13 at 22:11