【问题标题】:How do I configure when cobertura tests run in maven-cobertura-plugin?当 cobertura 测试在 maven-cobertura-plugin 中运行时如何配置?
【发布时间】:2012-01-16 23:15:51
【问题描述】:

为了微调哪些测试在哪些时间和哪些环境中运行,我们为 maven-surefire-plugin 设置了多个执行。我们将默认配置设置为跳过所有测试,然后为我们想要的执行启用它们。这本身对我们很有效。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
     <skip>true</skip>
  </configuration>
  <executions>
     <execution>
       <id>unit-tests</id>
       <phase>test</phase>
       <goals>
          <goal>test</goal>
       </goals>
       <configuration>
          <skip>false</skip>
          <includes>
             <include>**/*Tests.java</include>
          </includes>
          <excludes>
             <exclude>**/*IntegrationTests.java</exclude>
          </excludes>
       </configuration>
     <execution>
     <execution>
       <id>integration-tests</id>
       <phase>integration-test</phase>
       <goals>
          <goal>test</goal>
       </goals>
       <configuration>
          <skip>false</skip>
          <includes>
             <include>**/*IntegrationTests.java</include>
          </includes>
       </configuration>
     <execution>
   </executions>
</plugin>

当我将 maven-cobertura-plugin 添加到组合中时,我遇到了问题。 cobertura 目标运行,并成功地装备了我的课程。但是,没有运行测试。我认为这是因为 cobertura 正在运行的测试执行是被跳过的。但是,我找不到如何指定为此执行设置的阶段和目标。当我打开所有测试时,输出似乎表明这些测试仍在这些单元测试和集成测试阶段/目标中运行。

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>cobertura-maven-plugin</artifactId>
  <version>2.4</version>
  <configuration>
     <formats>
        <format>xml</format>
        <format>html</format>
     </formats>
  </configuration>
  <executions>
     <execution>
        <phase>package</phase>
        <goals>
           <goal>cobertura</goal>
        </goals>
     </execution>
  </executions>
</plugin>

我如何需要指定一个万无一失的执行,以便 cobertura 可以针对已检测的类运行它?

【问题讨论】:

  • 当您在没有 Cobertura 的情况下运行测试时,您如何告诉 maven 使用不同的执行方式?您在使用个人资料吗?
  • unit-tests 在常规的test 阶段运行(因此,当我们执行mvn package 时),而integration-tests 在我们执行mvn install 时运行。我认为这是因为在这些处决中指定了阶段和目标,尽管我承认这可能是我的误解。我们确实使用配置文件来启用或禁用 Cobertura,但这些似乎与在这些其他测试之间进行选择无关。

标签: maven cobertura


【解决方案1】:

你会note from the docs那个cobertura:cobertura

  • 必须是wired as a report
  • 仪器、测试和生成报告
  • 在自己的生命周期 cobertura(不是 default 生命周期)中运行
  • 在运行之前调用生命周期阶段test

因此,相应地接线应该会自动导致仪器和测试。

【讨论】:

  • 是的,我想我已经完成了所有这些(可能应该包括报告部分)。因此,如果它在生命周期cobertura 中,是否有某种方法可以在我的执行中指定生命周期?正如我所说,检测确实似乎正在发生,它只是告诉我测试被跳过了。
  • 如果您按照建议 (mojo.codehaus.org/cobertura-maven-plugin/usage.html) 连接它,它将自动检测、运行测试然后生成报告。
  • 基本配置适用于精简项目,但在我的实际项目构建中仍然失败。所以似乎 pom 中的其他东西在干扰。
  • 你能够让它在 some 配置中工作是一个好的开始。从那个状态我建议添加just你的源代码(当然还有任何dependency对POM的修改)。看看 that 是怎么回事。然后进一步调整 POM。
  • 也许他在问什么,也是我想要做的。我可以通过使用“mvn cobertura:cobertura”构建来生成 cobertura 报告,但我的构建是使用“mvn clean install”运行的。这会运行 cobertura 测试来检查覆盖率,但不会生成报告。我希望(也许还有 OP)每次使用“mvn clean install”或“mvn clean package”构建时都会生成这些报告。这可能吗?
猜你喜欢
  • 2013-02-20
  • 2012-12-08
  • 2012-02-12
  • 1970-01-01
  • 2012-01-07
  • 2014-12-18
  • 2011-01-12
  • 2015-06-18
  • 1970-01-01
相关资源
最近更新 更多