Search code examples
javamavenunit-testingjunitmaven-surefire-plugin

maven surefire plugin - run all tests sequentially


For some reason, I can't get maven surefire plugin to run my tests sequentially.

I use a redis mock (https://github.com/kstyrc/embedded-redis) in my tests, and it works great, but I get errors like

Cannot run program "/tmp/1494421531552-0/redis-server-2.8.19" (in directory "/tmp/1494421531552-0"): error=26, Text file busy

Which I looked up and found that it probably has something to do with tests running in parallel and its problematic with this mock.

Current my my maven looks like this

           <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.1</version>
            <configuration>
                <trimStackTrace>false</trimStackTrace>
                <useFile>false</useFile>
                <reuseForks>false</reuseForks>
                <forkCount>1</forkCount>
            </configuration>

I want to make sure all my tests run sequentially (one after another) - that means that every test method of every class runs alone.

How can I achieve that?


Solution

  • The only way to ensure the order of the unit tests as far as i know is to have it in alphabetical order:

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

    This being said, instead i think you need to define in each test an @After method that stops the redis mock (and actually wait until it is stopped), so that the new test can start up the redis mock in the @Before method without a conflict