Marcin Kunert
Marcin Kunert

Reputation: 6285

JUnit 5 test execution ordered by tag

Is it possible to change the order of test execution based on @Tag? I want to have all the tests marked with @Tag("fast") executed before @Tag("slow").

Im interested in solutions for IntelliJ IDEA and Maven. Both do not care about the order in which the tags are configured.

My config for Maven:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.0</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.2.0</version>
        </dependency>
    </dependencies>
    <configuration>
        <properties>
            <includeTags>fast,slow</includeTags>
        </properties>
    </configuration>
</plugin>

I guess my best bet is to run the suites separately.

Upvotes: 2

Views: 848

Answers (1)

Nicolai Parlog
Nicolai Parlog

Reputation: 51040

JUnit Jupiter only makes a single pass over the test classes and executes all tests whose tag is active, so it does not order. For a tool to order tests by tags, it would have to run JUnit several times, once for each tag, but no tool does that out of the box.

In IntelliJ you can run all tests with a specific tag (earch for "@Tag"), so you could generate several such configuration. In Maven you could give Surefire and Failsafe different tags to execute, although that would only buy you two executions instead of one.

Upvotes: 1

Related Questions