Separate test execution with Maven

Viewed 165

Is it possible to configure Maven so that it executes all test classes separately as I would execute them from command line:

mvn -Dtest=Test1 test && mvn -Dtest=Test2 test && mvn -Dtest=Test3 test

I thought it could be achievable with maven surefire plugin. With configuration like:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <executions>
                    <execution>
                        <id>test1</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/Test1.java</include>
                            </includes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test2</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/Test2.java</include>
                            </includes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test3</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/Test3.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

But it doesn't work

1 Answers

The option

        <configuration>
            <reuseForks>false</reuseForks>
        </configuration>

solved the problem as it forced each test to run on a separate VM

Related