Skip to content

Introduce support for parallel test execution in declarative test suites #964

@casid

Description

@casid

I'm currently migrating a project from JUnit4 to JUnit5 (Branch: https://github.com/casid/mazebert-ladder/tree/junit5).

A feature of the JUnit4 tests is that I can run all unit tests in parallel. This is an essential feature since it a) chops down the test execution time significantly and b) prevents developers from adding shared state to unit tests.

In JUnit4 with the help of junit-toolbox:

@RunWith(ParallelSuite.class)
@SuiteClasses("**/*Test.class")
public class UnitTestSuite {
}

I wished JUnit5 to support something like this:

@Suite(parallel = true)
@SuiteClasses("**/*Test")
public class UnitTestSuite {
}

But I couldn't find anything that looked even slightly like it.

I think suites could greatly improve configuration options for test executions. In fact, it would remove the need for external tools to implement the same features (e.g. parallel execution / test discovery). You could simply point maven-surefire, gradle or IntelliJ to the TestSuite(s) you want to execute.

Integration tests could benefit from this too:

@Suite(parallel = true)
@SuiteClasses("**/*IT")
@IncludeTags("parallel")
public class ParallelIntegrationTestSuite {
    @BeforeClass
    public static void setUp() throws Exception {
        TestDataSourceProvider.instance.prepare();
    }

    @AfterClass
    public static void tearDown() throws Exception {
        TestDataSourceProvider.instance.dispose();
    }
}

I would love to have something like this in JUnit5! Currently I have some mixed feelings how to proceed with adopting JUnit5 (great new features like nested tests) vs JUnit4 (great test execution control).

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions