How do I control the order of execution of tests in Maven?

You can’t specify the run order of your tests.

A workaround to do this is to set the runOrder parameter to alphabetical.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <runOrder>alphabetical</runOrder>
    </configuration>
</plugin>

and then you need to have rename your tests to obtain the expected order.

However it isn’t a good idea to have dependent tests. Unit tests must be fIrst.

Leave a Comment