JUnit4 Threaded Tests With Priorities

All of our unit and integration junit tests use our new test Runner FSQueuedTestClassRunner. This has proved to significantly reduce our test run time by taking advantage of multi-core machines. Some of our tests are “more important” or are “more likely to fail” due to their complexity. To get earlier feedback for these tests, we have add a prioritization feature. By annotating a test class with “@FSTestClassRunnerPriority(priority=?)” we can effect the order for which it is run. The default priority for all tests is 0. Tests with higher priority numbers get run first. Below is an example:

//High priority Test
@RunWith(FSQueuedTestClassRunner.class)
@FSTestClassRunnerPriority(priority=10)
public class FileHelperTestHighPriority {
...
}

//Low priority Test
@RunWith(FSQueuedTestClassRunner.class)
@FSTestClassRunnerPriority(priority=-100)
public class FileHelperTestLowPriority {
...
}

The current implementation hard codes the priority. Maybe someday we will add a different implementation that adjust the priorities based on previous test failures.
Kevin

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply