Maven:如何解决 Surefire 的 -Dtest 覆盖包含和排除问题?
我在一个配置文件中有两个肯定的执行 - 它们需要不同的配置。 当我运行 -Dtest=... 时,匹配的测试运行两次 - 每次执行一次。
如何让测试只运行一次? 或者更好的是,我怎样才能确保surefire遵循包含和排除? (一次执行将运行 0 次测试;我会使用 -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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这听起来像是对 maven-surefire-plugin 的滥用,因为你似乎有某种集成测试应该由 maven-failsafe-plugin 代替。通过使用它们,您将自动获得不同的单元测试和集成测试配置。 maven-surefire-plugin 旨在运行单元测试,而 maven-failsafe-plugin 旨在运行集成测试。此外,您的配置看起来需要不同类型的集成测试,换句话说,这意味着有多个集成测试模块。
对于集成测试运行来说,这将是最好的选择。
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.
And this will be the best thing to have different configurations for integration test runs.
maven-surefire-plugin 版本 2.12 修复了此问题。
http://jira.codehaus.org/browse/SUREFIRE-806)
(请参阅 v2.12 中添加的更改:
引用 John Casey 对上面 JIRA 链接的评论:
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: