【问题标题】:How to use Maven Surefire plug-in with different groups for test and integration-test?如何使用 Maven Surefire 插件与不同的组进行测试和集成测试?
【发布时间】:2009-01-05 10:11:31
【问题描述】:

我想将 testngMavenSurefire plug-in 一起使用。这个想法是用integrationTest 组标记一些测试并运行插件两次:目标test 不包括integrationTest 组和目标integration-test 仅包括integrationTest 组。

我找到了一些 material 用于为两个目标运行插件并且有效,但第二次运行的组不起作用(不执行任何测试)。

这里是我pom.xml的build元素中的插件配置:

  <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 组被忽略。

【问题讨论】:

    标签: maven-2 maven-plugin testng surefire


    【解决方案1】:

    我明白了——烦人的配置实现!

    &lt;excludedGroups/&gt; 不会覆盖&lt;excludedGroups&gt;integrationTest&lt;/excludedGroups&gt;。您需要指定任何(未知)组,例如 &lt;excludedGroups&gt;none&lt;/excludedGroups&gt;

    【讨论】:

    • excludedGroups 不适用于 TestNG 5.14.1 - 请改用 5.14.2!
    • 使用 Surefire 2.18.1 和 JUnit 4.10,我收到错误 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (integration-test) on project example-project: Execution integration-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: There was an error in the forked process [ERROR] java.lang.RuntimeException: Unable to load category: none。似乎您覆盖的组必须至少存在,即使它没有在任何地方使用。我使用 public interface SystemTest extends IntegrationTest 执行此操作并排除 that 类别。
    【解决方案2】:

    Failsafe plugin 是执行此操作的最佳方式(您发布此问题时它可能不可用)。它将集成测试阶段添加到构建生命周期。它允许您在测试之前和之后运行设置和拆卸活动,例如,这对于管理嵌入式容器很有用。

    【讨论】:

    • 您可能是对的:Maven Central 搜索将最古老的 maven-failsafe-plugin 工件日期定为 2010 年 1 月 12 日。我认为,从那时起,它就成为了该问题的首选解决方案。
    猜你喜欢
    • 1970-01-01
    • 2014-08-30
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2014-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多