当前位置: 首页 > 知识库问答 >
问题:

Maven Jacoco:Jacoco:报告没有从pom.xml中选择配置

令狐经武
2023-03-14

我正在尝试为我的单元测试分离jacoco覆盖率分析的生成。

我已经创建了(在我的pom.xml中)一个特定于它的html" target="_blank">配置文件,因为我不想在我的所有环境中运行测试。

这是我的pom.xml中的概要文件部分:

<profile>
            <id>unit-tests</id>

            <activation>
                <property>
                    <name>env.SPRING_BOOT_ACTIVE_PROFILE</name>
                    <value>!prod</value>
                </property>
            </activation>

            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <scope>runtime</scope>
                </dependency>

                <!--embedded tomcat server (needed to run tests)-->
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                    <scope>provided</scope>
                </dependency>

                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-test</artifactId>
                    <scope>test</scope>
                </dependency>

            </dependencies>

            <build>
                <plugins>
                    <!-- Code coverage plugin -->
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.8.2</version>
                        <executions>
                            <!--
                                Prepares the property pointing to the JaCoCo runtime agent which
                                is passed as VM argument when Maven the Surefire plugin is executed.
                            -->
                            <execution>
                                <id>pre-unit-test</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <configuration>
                                    <!-- Sets the path to the file which contains the execution data. -->
                                    <destFile>${jacoco.ut.execution.data.file}</destFile>
                                    <!--
                                        Sets the name of the property containing the settings
                                        for JaCoCo runtime agent.
                                    -->
                                    <propertyName>surefireArgLine</propertyName>
                                </configuration>
                            </execution>
                            <!--
                                Ensures that the code coverage report for unit tests is created after
                                unit tests have been run.
                            -->
                            <execution>
                                <id>post-unit-test</id>

                                <goals>
                                    <goal>report</goal>
                                </goals>
                                <configuration>
                                    <!-- Sets the path to the file which contains the execution data. -->
                                    <dataFile>${jacoco.ut.execution.data.file}</dataFile>
                                    <!-- Sets the output directory for the code coverage report. -->
                                    <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
                                </configuration>
                            </execution>
                            <!--
                                Prepares the property pointing to the JaCoCo runtime agent which
                                is passed as VM argument when Maven the Failsafe plugin is executed.
                            -->

                        </executions>

                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <!-- this dependency is only needed to fix a bug in open jdk 8 (test)-->
                            <useSystemClassLoader>false</useSystemClassLoader>
                            <argLine>${surefireArgLine}</argLine>
                        </configuration>
                    </plugin>

                </plugins>

            </build>

        </profile>

第一次按此顺序运行命令mvn清洁mvn测试mvn雅各科:报告

运行命令mvn test后,Jacoco在属性"jacoco.ut.execution.data.file"指定的位置正确生成包含覆盖率信息的文件

但是当我运行命令mvn Jacoco: report时,我收到了这个错误。

-jacoco-maven-plugin:0 . 8 . 2:report(default-CLI)@ spring bootseed-< br >由于缺少执行数据文件,跳过JaCoCo执行。

我试着移开线

<destFile>${jacoco.ut.execution.data.file}</destFile>

从准备代理执行的配置中,通过这种方式,雅各将文件写入默认位置(目标/jaco.exec)

通过这种设置,jacoco可以正确地选择文件,并在默认位置(site/jacoco)生成报告。

由于这些原因,我认为Jacoco在运行mvn Jacoco时没有选择pom的配置:报告

我怎样才能解决这个问题?

先谢谢你

共有1个答案

拓拔俊德
2023-03-14

尝试将“argLine”定义为一个专家属性,并从此处提到的肯定和哈科插件中删除:https://docs.sonarqube.org/display/PLUG/Usage 与SonarJava的JaCoCo。它对我有用。

 类似资料:
  • pylint的输出指出: nltk/nltk/标签/感知机。py:203:[W1202(记录格式插值),Perceptrontager.train]在记录函数中使用%格式,并将%参数作为参数传递 但看看代码https://github.com/nltk/nltk/blob/develop/nltk/tag/perceptron.py#L203,没有使用任何字符串格式: 我是否遗漏了什么或误解了W1

  • 我在运行这个代码时遇到了一个问题。我总是收到这样的消息:“文档没有页面”,在pdf文件中有一个空白页。 注意:我使用的是NetBeans IDE7.2测试版。 null 这是我的代码: 我真的很感激你的帮助。

  • 我正在从. jasper文件加载jasper报告文件以提高性能,如下所示。 但是我现在有一个要求,动态形成的查询必须设置为. jasper(编译)文件。有没有办法做同样的事情?

  • 问题内容: 我正在尝试从以下查询中获取行数。我只得到行计数为1,但有35条记录。您能否让我知道如何从内部查询中获取计数? 谢谢 问题答案: 您缺少FROM,需要为子查询指定别名。

  • 使用指南 - 数据报告 - 概述 - 为什么有些报告没有权限 在百度统计中,无权限报告所属的站点应是“权限站点”,权限站点在右上角站点选择下拉框中有“权限站点”的字样标注,如图所示: 权限站点是其他账户将其自有站点授权给您查看数据的站点,在授权时定义了您的查看和设置权限。如果此报告无权限,说明授权发起者未授权给您。 您可以在“管理->网站列表”的“权限网站”标签下,查看该站点的权限来源账户,如需开

  • 使用指南 - 数据报告 - 百度推广 - 为什么推广报告中没有数据 如果确认代码安装正确(点此查看如何检查代码安装正确),那么百度推广报告中没有数据或者数据显示不全,可能有以下原因: 1、您的查看时间为添加代码的当天,此时百度推广数据尚未生成,要等次日查看; 2、如果是某个特定的计划、单元或关键词没有数据,请检查: (1)您是否在全部的百度推广URL中安装了代码? 请确保在全部的百度推广URL都安