Thursday, 7 March 2013

Ordering Surefire Tests on Linux and Windows

Although there is important for the tests to run independently, sometimes there is need to preserve order for executing with Maven Surefire. Default ordering used by this Maven plugin is filesystem, which means unit tests will execute in the order they are presented in the file system. Problem is that NTFS and Linux file systems do not provide same ordering - NTFS provides alphabetical ordering of files.

The solution is to explicitly set the test ordering for the Maven Surefire tests execution to alphabetical if you need the project build be same on both systems and if the tests execution order is important.

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