1

I have a big mess with 100 tests in one class and running all of them by clicking "Test project (...). They run in a random order and I would like them to run in a specific order - from beginning to the end, the same order that I wrote them. In eclipse it's not a problem because eclipse just works like that, how to do it in netbeans?

Any help will be appreciated.

Edit (due to answers): Tests order is required for the clearance of the log. They are independent.

Doszi89
  • 357
  • 2
  • 5
  • 20

4 Answers4

3

If your tests needs to run in a specific order, something is wrong with your design. 2 test that needs to run one after another are 1 test. Consider this before searching for a solution.

check this https://blogs.oracle.com/mindless/entry/controlling_the_order_of_junit

Chen Kinnrot
  • 20,609
  • 17
  • 79
  • 141
2

Having tests depending on other tests 99.9% of the time a very bad idea. Unit tests should be independent from each other, as otherwise you might have a cascade of errors, or (even worse) one test failing because something another test did sometime before.

If you still want to go through this pain, you'll need to use a different unit testing framework (such as TestNG - see dependsOnMethods) which supports test dependencies.

Junit doesn't support this feature because it's seen by many as a bad practice (for very good reasons).

Augusto
  • 28,839
  • 5
  • 58
  • 88
  • My tests are independent. I need them in order because of clearance of xml log. Thank you for you answer, I consider using another environment, if there's no other way to solve it. – Doszi89 Jul 12 '12 at 09:10
  • Doszi, that clearance **is** a dependency. Can you think of a way of breaking it so the tests don't need to be run in a specific sequence? – Augusto Jul 12 '12 at 11:58
2

The next JUnit release will support ordering of test methods. The standard Maven Surefire Plugin supports ordering of test methods already.

Stefan Birkner
  • 24,059
  • 12
  • 57
  • 72
1

Netbeans has good integration with ant build files. You could write a specific ant target that could execute each test in order.

Jayan
  • 18,003
  • 15
  • 89
  • 143