What does the "default-test" stand for in the maven-surefire plugin
Asked Answered
C

2

18

I have defined the following configuration in my pom for surefire with TestNg:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12</version>
            <configuration>
                <skipTests>${skip-all-tests}</skipTests>
            </configuration>
            <executions>
                <execution>
                    <id>unit-tests</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>${skip-unit-tests}</skip>
                        <groups>unit</groups>

                        <excludedGroups>integration</excludedGroups>
                    </configuration>
                </execution>
                <execution>
                    <id>integration-tests</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>${skip-integration-tests}</skip>
                        <groups>integration</groups>
                        <excludedGroups>unit</excludedGroups>
                    </configuration>
                </execution>
            </executions>
        </plugin>

But it seems the two executions are always preceded by a "default-test" run which seems to run every @test annotated method (at least I think so).

--- maven-surefire-plugin:2.12:test (default-test) @ my-project

For example running "mvn test" on the project, two test executions take place. The "default-test" and the "unit-test".

Could someone explain this a little more to me? Can this be disabled or controlled (configured what is tested and what not)?

Cerallua answered 13/8, 2012 at 13:25 Comment(2)
Take a look in your resulting pom via mvn help:effective-pom. Furthermore the best thing to define such thing is to put it into pluginManagement and you should run integration tests by maven-failsafe-plugin and NOT via maven-surefire-plugin.Tipcat
Thanks, that already cleared out a lot for me! If you put your comment in a answer form I will award you the credits.Cerallua
C
26

People wanted to have a way to override the default built-in executions of plugins within Maven.

Maven 3 (or it may have been introduced as early as 2.1.0 or 2.2.0) solved this by defining a default execution id for each plugin execution added to the effective pom by the packaging's lifecycle.

The name of this implicit id is always default-_____ I cannot recall the exact rule that it is generated for.

You can therefore override the packaging's injected executions by defining a matching execution.

To solve your case I would either change <id>unit-tests</id> to <id>default-test</id> or add

            <execution>
                <id>default-test</id>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </execution>

either will have the same effect, though the <id>unit-tests</id> to <id>default-test</id> solution will be slightly more performant as you only need to invoke two executions of surefire.

The other thing I would point out is you would probably be better off using maven-failsafe-plugin to execute your integration tests as at some point in time you may want to do some stuff pre & post integration testing, and failsafe is designed for that use case (though it should be trivial to switch further down the line)

Chilblain answered 14/8, 2012 at 8:27 Comment(0)
Q
5

Alternatively to the Stephen's solution, if you don't want the following message to be displayed in the log (which in fact is a bit misleading since you are not skipping tests):

[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ service-template ---
[INFO] Tests are skipped.

...then go this way:

                <execution>
                    <id>default-test</id>
                    <phase>none</phase>
                </execution>
Quadrivalent answered 27/6, 2019 at 12:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.