How to control test class execution order in JUnit 5 suites? #5085
-
| How to control test class execution order in JUnit 5 suites?** I'm organizing my tests using JUnit 5's Here's my current suite setup: import org.junit.platform.suite.api.SelectClasses; import org.junit.platform.suite.api.Suite; @Suite @SelectClasses({ Test1.class, // Should run FIRST Suite1.class, // Should run after Test1 but before Test2 Suite2.class, Suite3.class, Test2.class // Should run LAST }) public class SuiteA { }The subordinate suites look like: @Suite @SelectClasses({TestXxx.class, SuiteXxx.class}) public class Suite1 { }My test dependencies require that:
What I've tried/researched:
Question: I'm using JUnit 5.8+/Jupiter with the junit-platform-suite engine. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
| That's currently not possible since If you're looking for a lifecycle hook to run some code before the first test in the suite (or after the last), have you considered using |
Beta Was this translation helpful? Give feedback.
Where is this ordering requirement coming from? Is it only due to certain test classes requiring certain setup/teardown logic? Assuming your tests are all written using JUnit Jupiter, I think you might not even need the Suite engine, but use the lazy resource creation pattern from the User Guide (see
HttpServerExtension). Each test class/method could then get the resources it needs injected and the Jupiter engine would take care of cleaning up after all of them are done.