如何使用Maven Surefire插件与不同的组进行测试和集成测试?
我想将 testng 与 Surefire 插件 ”Maven。 这个想法是用组 integrationTest
标记一些测试,并运行插件两次:针对目标 test
排除组 integrationTest
和针对目标integration-test
仅包含 integrationTest
组。
我找到了一些材料用于为这两个目标运行插件有效,但第二次运行的组不起作用(不执行任何测试)。
这是我的 pom.xml
的构建元素中的插件配置:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludedGroups>integrationTest</excludedGroups>
<reportFormat>brief</reportFormat>
<trimStackTrace>true</trimStackTrace>
<useFile>false</useFile>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<groups>integrationTest</groups>
<excludedGroups/>
<reportsDirectory>${project.build.directory}/surefire-reports/integration</reportsDirectory>
</configuration>
</execution>
</executions>
</plugin>
有什么想法吗? mvn Integration-test
按预期运行所有单元测试(不包括 integrationTest
组),但第二次测试运行仅写入:
运行测试套件
测试运行:0,失败:0,错误:0,跳过:0,已用时间:0.562 秒
mvn test
的结果符合预期,测试运行并分组 integrationTest
被忽略。
I want to use testng with the Surefire plug-in of Maven. The idea is to tag some tests with a group integrationTest
and run the plug-in twice: for goal test
excluding the group integrationTest
and for goal integration-test
including the group integrationTest
only.
I found some material for running the plug-in for both goals and that works, but the group for the second run does not work (no test is executed).
Here is the plug-in configuration in the build element of my pom.xml
:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludedGroups>integrationTest</excludedGroups>
<reportFormat>brief</reportFormat>
<trimStackTrace>true</trimStackTrace>
<useFile>false</useFile>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<groups>integrationTest</groups>
<excludedGroups/>
<reportsDirectory>${project.build.directory}/surefire-reports/integration</reportsDirectory>
</configuration>
</execution>
</executions>
</plugin>
Any idea? mvn integration-test
runs all unit tests as expected (excluding the group integrationTest
) but the second test run just writes:
Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.562 sec
The Result of mvn test
is as expected, tests run and group integrationTest
is ignored.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我明白了 - 令人恼火的配置实现!
不会覆盖integrationTest
。 您需要指定任何(未知)组,例如none
。I got it - irritating configuration implementation!
<excludedGroups/>
does not override<excludedGroups>integrationTest</excludedGroups>
. You need to specify any (unknown) group instead,<excludedGroups>none</excludedGroups>
for example.Failsafe 插件 是执行此操作的最佳方法(它可能当您发布此问题时尚不可用)。 它在构建生命周期中添加了集成测试阶段。 它允许您在测试之前和之后运行设置和拆卸活动,这对于管理嵌入式容器等很有用。
The Failsafe plugin is the best way to do this (it may not have been available when you posted this question). It adds an integration-test phase to the build lifecycle. It allows you to have setup and teardown activities run before and after the tests, which is useful for managing an embedded container, for example.