如何使用Maven Surefire插件与不同的组进行测试和集成测试?

发布于 2024-07-11 09:40:57 字数 1866 浏览 11 评论 0原文

我想将 testngSurefire 插件 ”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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぇ气 2024-07-18 09:40:57

我明白了 - 令人恼火的配置实现!

不会覆盖 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.

彡翼 2024-07-18 09:40:57

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文