问题
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.
回答1:
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
回答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).
回答3:
The next JUnit release will support ordering of test methods. The standard Maven Surefire Plugin supports ordering of test methods already.
回答4:
Netbeans has good integration with ant build files. You could write a specific ant target that could execute each test in order.
来源:https://stackoverflow.com/questions/11448001/junit-changing-sequence-of-test-running