未生成jacoco-ut.exec覆盖报告

发布于 2025-02-03 04:08:21 字数 2239 浏览 3 评论 0原文

Java 1.8。 Maven 3.8。我想生成Junit测试的覆盖报告。因此,我在POM.xml

                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.7.4.201502262128</version>
                        <executions>
                            <execution>
                                <id>prepare-ut-agent</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <configuration>
                                    <destFile>${project.build.directory}/jacoco-ut.exec</destFile>
                                    <propertyName>jacoco.agent.ut.arg</propertyName>
                                    <append>true</append>
                                </configuration>
                            </execution>
                            <execution>
                                <id>prepare-it-agent</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <configuration>
                                    <destFile>${project.build.directory}/jacoco-it.exec</destFile>
                                    <propertyName>jacoco.agent.it.arg</propertyName>
                                    <append>true</append>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

开放终端中使用此操作,并以此方式运行测试:

mvn test -Dtest=com.my_company.myproject.ComponentServiceTest

测试成功完成。但是要生成的报道报告。文件jacoco-it.exec在目标文件夹中不存在

Java 1.8. Maven 3.8. I want to generate coverage report of junit tests. So I use this in my pom.xml

                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.7.4.201502262128</version>
                        <executions>
                            <execution>
                                <id>prepare-ut-agent</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <configuration>
                                    <destFile>${project.build.directory}/jacoco-ut.exec</destFile>
                                    <propertyName>jacoco.agent.ut.arg</propertyName>
                                    <append>true</append>
                                </configuration>
                            </execution>
                            <execution>
                                <id>prepare-it-agent</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <configuration>
                                    <destFile>${project.build.directory}/jacoco-it.exec</destFile>
                                    <propertyName>jacoco.agent.it.arg</propertyName>
                                    <append>true</append>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

Open terminal and run test like this:

mvn test -Dtest=com.my_company.myproject.ComponentServiceTest

Tests success finish. But coverage report to generate. File jacoco-it.exec is not exist in target folder

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

去了角落 2025-02-10 04:08:21

pom.xml缺少报告目标,如@rajani-b

这是报告目标的配置。

<execution>
  <id>report</id>
  <goals>
    <!--
      Generate coverage reports in xml,csv,html formats
      in folder ${project.build.directory}/site/jacoco
    -->
    <goal>report</goal>
  </goals>
</execution>

以下是jacoco-maven-plugin的完整&lt; plugin&gt;供参考。

<plugin>
   <groupId>org.jacoco</groupId>
   <artifactId>jacoco-maven-plugin</artifactId>
   <version>0.7.4.201502262128</version>
   <executions>
      <execution>
         <id>prepare-ut-agent</id>
         <phase>process-test-classes</phase>
         <goals>
            <goal>prepare-agent</goal>
         </goals>
         <configuration>
            <propertyName>jacoco.agent.ut.arg</propertyName>
            <append>true</append>
         </configuration>
      </execution>
      <execution>
         <id>prepare-it-agent</id>
         <phase>pre-integration-test</phase>
         <goals>
            <goal>prepare-agent</goal>
         </goals>
         <configuration>
            <propertyName>jacoco.agent.it.arg</propertyName>
            <append>true</append>
         </configuration>
      </execution>
      <execution>
         <id>prepare-agent</id>
         <goals>
            <goal>prepare-agent</goal>
         </goals>
      </execution>
      <execution>
         <id>report</id>
         <goals>
            <!--
              Generate coverage reports in xml,csv,html formats
              in folder ${project.build.directory}/site/jacoco
            -->
            <goal>report</goal>
         </goals>
      </execution>
   </executions>
</plugin>

The pom.xml is missing the report goal as mentioned in the comment by @rajani-b.

Here is the configuration for the report goal.

<execution>
  <id>report</id>
  <goals>
    <!--
      Generate coverage reports in xml,csv,html formats
      in folder ${project.build.directory}/site/jacoco
    -->
    <goal>report</goal>
  </goals>
</execution>

Below is the complete <plugin> section for jacoco-maven-plugin for reference.

<plugin>
   <groupId>org.jacoco</groupId>
   <artifactId>jacoco-maven-plugin</artifactId>
   <version>0.7.4.201502262128</version>
   <executions>
      <execution>
         <id>prepare-ut-agent</id>
         <phase>process-test-classes</phase>
         <goals>
            <goal>prepare-agent</goal>
         </goals>
         <configuration>
            <propertyName>jacoco.agent.ut.arg</propertyName>
            <append>true</append>
         </configuration>
      </execution>
      <execution>
         <id>prepare-it-agent</id>
         <phase>pre-integration-test</phase>
         <goals>
            <goal>prepare-agent</goal>
         </goals>
         <configuration>
            <propertyName>jacoco.agent.it.arg</propertyName>
            <append>true</append>
         </configuration>
      </execution>
      <execution>
         <id>prepare-agent</id>
         <goals>
            <goal>prepare-agent</goal>
         </goals>
      </execution>
      <execution>
         <id>report</id>
         <goals>
            <!--
              Generate coverage reports in xml,csv,html formats
              in folder ${project.build.directory}/site/jacoco
            -->
            <goal>report</goal>
         </goals>
      </execution>
   </executions>
</plugin>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文