Search code examples
junitjunit4junit5runner

How run test suite JUnit5-based?


I want to create runner for my test classes that based on JUnit-5.

In the first I tried to use with this construction.

@RunWith(JUnitPlatform.class)
@SelectClasses(UserAPITest.class)
public class UserAPITestRunner {
}

But in doesn't work. If I understand correctly, then with the help of such a runner I can run JUnit4 based.

How we can run suite JUnit5 tests?


Solution

  • Techically, if you are using @RunWith(JUnitPlatform.class) that is a suite in JUnit 5. It just uses JUnit 4 to launch the JUnit 5 Platform.

    From the documentation:

    Test classes and suites annotated with @RunWith(JUnitPlatform.class) cannot be executed directly on the JUnit Platform (or as a "JUnit 5" test as documented in some IDEs). Such classes and suites can only be executed using JUnit 4 infrastructure.