Search code examples
javaunit-testingtestingjunitjunit5

How to set custom test execution order for a test suite in JUnit5?


I have a large set of tests on JUnit5, which I run in parallel in several threads. There is also information about the time of each test. I want to run at the beginning of the longest tests, and leave the fastest at the end to optimize common execution time.

I have not found a way to do this in JUnit5.

In version 5.4 there is an org.junit.jupiter.api.MethodOrderer interface which allows you to write a test sorter within a test class. And connect to the test class via the annotation org.junit.jupiter.api.TestMethodOrder.

I would like something similar, but globally, for the whole test suite.


Solution

  • What you're asking for is unfortunately not currently possible in JUnit 5 (i.e., either on the JUnit Platform or within JUnit Jupiter).

    There is however an open issue dedicated to this topic. So feel free to chime in there.