Ondra Žižka
Ondra Žižka

Reputation: 46816

Maven: How to workaround Surefire's -Dtest overriding includes and excludes?

I have two surefire executions in one profile - they need different config. When I run -Dtest=..., the matching test is running twice - once for each execution.

How can I make the test run only once? Or better, how can I make surefire follow includes and excludes? (One execution would run 0 tests; I'd use -DfailIfNoTest=false.)

    <profile>
        <id>clustering.integration.tests.profile</id>
        <activation>
            <property>
                <name>clustering.integration.tests</name>
                <value>true</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <executions combine.children="append">

                        <!-- Disable default-test execution. -->
                        <execution>
                            <id>default-test</id>
                            <goals><goal>test</goal></goals>
                            <phase>none</phase>
                        </execution>

                        <!-- Single node clustering tests. -->
                        <execution>
                            <id>tests-clustering-single-node.surefire</id>
                            <phase>test</phase>
                            <goals><goal>test</goal></goals>
                            <configuration>
                                <includes>
                                    <include>org/jboss/as/test/clustering/single/**/*TestCase.java</include>
                                </includes>
                            </configuration>
                        </execution>

                        <!-- Multi node clustering tests. -->
                        <execution>
                            <id>tests-clustering-multi-node.surefire</id>
                            <phase>test</phase>
                            <goals><goal>test</goal></goals>
                            <configuration>
                                <includes>
                                    <include>org/jboss/as/test/clustering/cluster/**/*TestCase.java</include>
                                </includes>
                            </configuration>
                        </execution>

                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

Upvotes: 2

Views: 1290

Answers (2)

khmarbaise
khmarbaise

Reputation: 97437

This sounds like a misuse of the maven-surefire-plugin, cause you seemed to have some kind of integration-tests which should be done by the maven-failsafe-plugin instead. By using them you automatically have different configurations for unit- and integration tests. The maven-surefire-plugin is intended to run unit tests where as the maven-failsafe-plugin is intended to run integration tests. Furthermore you configuration looks like you need different kind of integration-tests which means in other word to have several integration-tests modules.

 +-- pom.xml
 +-- module-1
 +-- module-2
 +-- integration-test-single-node
 +-- integration-test-multi-node
 ...

And this will be the best thing to have different configurations for integration test runs.

Upvotes: 2

Nicholas Daley-Okoye
Nicholas Daley-Okoye

Reputation: 2407

Version 2.12 of the maven-surefire-plugin has a fix for this problem. (See http://jira.codehaus.org/browse/SUREFIRE-806)

Describing the changes added to v2.12: Quoted from John Casey's comment on the JIRA link above:

Also, in cases where there are multiple test execution blocks, to avoid running a specified test in the wrong block, the existing includes/excludes are now honored...the specified tests now act as a refining filter on these includes/excludes. This means that in cases where there are multiple test-execution blocks, you cannot run a test that wouldn't ordinarily be run by just using -Dtest=... any more.

In cases where there is only a single test-execution block, the specified tests should override the includes as before.

Upvotes: 1

Related Questions