maven-surefire插件中的“默认测试”代表什么?

时间:2012-08-13 13:25:43

标签: maven-3 testng maven-surefire-plugin

我已经在我的pom中使用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>

但似乎两个执行总是先于“默认测试”运行,它似乎运行每个@test带注释的方法(至少我认为是这样)。

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

例如,在项目上运行“mvn test”,就会发生两次测试。 “默认测试”和“单元测试”。

有人可以向我解释一下吗? 这可以被禁用或控制(配置什么是测试的,什么不是)?

2 个答案:

答案 0 :(得分:16)

人们希望有办法覆盖Maven中插件的默认内置执行。

Maven 3(或者它可能早在2.1.0或2.2.0中引入)通过为包装生命周期中添加到有效pom的每个插件执行定义默认执行ID来解决这个问题。

此隐式ID的名称始终为default-_____我无法回想起为其生成的确切规则。

因此,您可以通过定义匹配的执行来覆盖包装的注入执行。

要解决您的情况,我可以将<id>unit-tests</id>更改为<id>default-test</id>或 添加

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

要么具有相同的效果,尽管<id>unit-tests</id><id>default-test</id>解决方案会稍微提高性能,因为您只需要调用两次surefire执行。

我要指出的另一件事是你可能最好使用maven-failsafe-plugin来执行集成测试,因为在某些时候你可能想要做一些事情。后整合测试,故障安全是针对该用例设计的(尽管进一步切换线应该是微不足道的)

答案 1 :(得分:0)

作为斯蒂芬解决方案的替代方案,如果您不希望在日志中显示以下消息(实际上,由于您没有跳过测试,这也会引起误解):

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

...然后走这边:

                <execution>
                    <id>default-test</id>
                    <phase>none</phase>
                </execution>
相关问题