How can I set the order that the tests are run in?
AFAIK there is no easy way to set the order for any JUnit 4 tests using the @Test
annotation. The only thing you can do is have one @Test
method which calls the actual test methods in the order you want.
should not do that since it won't give you visibility to the test stats
What test stats do you need that this method wouldn't provide? If a test fails, you have the full stacktrace.
It will miss the actual number of tests being run. For example, if we have 10 tests in a class, it will then report all of them as 1 test case. Also if one test fails, all other tests will not run that should follow.
Junit has no specific order to run test cases. Your best option is to never rely on a previous testcase.
But if it is not possible, you can create one test method and order execution within that method.
But I strongly recommend not trying to order your testcases.
I agree with this comment. Build your testcases such that they do not have direct dependencies, i.e. don't require test A to run before test B runs. If they both have some preconditions that are required, then factor out a common method called by both independently.
I have added enhancement into plt-8.3.1 to let developer order UI test cases.
To order test case you need to add OrderedUITest to test method annotation:
@Test
@OrderedUITest(order = 1)
public void testMultipleMvmtReportForBulkPrint() throws Exception {
....
}
All test cases without OrderedUITest annotation will run after ordered.