如何在maven-cobertura-plugin中运行cobertura测试?

CPh*_*lps 9 cobertura maven

为了微调在哪些时间以及在哪些环境中运行哪些测试,我们为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>
Run Code Online (Sandbox Code Playgroud)

当我将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>
Run Code Online (Sandbox Code Playgroud)

我如何指定一个surefire执行,以便cobertura将针对检测类运行它?

Sri*_*ran 2

您将从文档中注意到cobertura:cobertura

  • 必须以报告形式发送
  • 仪器、测试并生成报告
  • cobertura在它自己的生命周期(而不是default生命周期)中运行
  • test在运行自身之前调用生命周期阶段

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

  • 也许他所要求的,也是我正在努力做的。我可以通过使用“mvn cobertura:cobertura”构建来生成cobertura报告,但我的构建是使用“mvn clean install”运行的。这确实会运行 cobertura 测试来检查覆盖范围,但不会生成报告。我希望(也许OP也)在每次使用“mvn clean install”或“mvn clean package”构建时生成这些报告。那可能吗? (2认同)