2

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?

Ofek Agmon
  • 5,040
  • 14
  • 57
  • 101

1 Answers1

3

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

taygetos
  • 3,005
  • 2
  • 21
  • 29
  • thank you. Is there a way to define for all the classes under specific pom to be NotThreadSafe? I have a bunch of classes that all extend a BaseTest class, and I want all of them to be executed sequentially. Can I set NotThreadSafe in pom.xml to affect all of its classes? – Ofek Agmon Dec 31 '18 at 10:28
  • I think the NotThreadSafe annotation can only be used in the code, however check out this solution: https://stackoverflow.com/questions/24811430/exclude-specific-tests-from-being-run-in-parallel-in-junit – taygetos Jan 01 '19 at 15:41