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

Jacoco代码覆盖率报告显示Jenkins的覆盖率为0

阎星华
2023-03-14

Jacoco插件在jenkins报告中显示0%的覆盖率,但当我在本地系统中运行相同的命令时,Jacoco会正确生成报告。我正在使用以下命令:

mvn-s xyz/settings.xml-f xyz/xyz/pom.xml清洁安装org.jacoco

所以当我在jenkins中运行这个命令时,它会生成错误的报告。我已经检查了它在工作区目录对应的项目在詹金斯。它显示每个项目的0%覆盖率。但是当我在本地系统中运行相同的maven命令时,jachoco-maven会生成正确的覆盖报告。我可以看到它们是超文本标记语言格式的。

我的pom。xml有以下功能可以与maven一起运行jacoco:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.7.201606060606</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>

我正在使用以下工具:

jacoco-maven-plugin version 0.7.7
jenkins-jacoco-plugin version 2.0.1
apache-maven version 3.5.0

这也是我的jenkins控制台日志,我得到后,maven命令完成。

[JaCoCo plugin] Collecting JaCoCo coverage data...
[JaCoCo plugin] **/**.exec;**/target/classes;**/src; locations are configured
[JaCoCo plugin] Number of found exec files for pattern **/**.exec: 0
[JaCoCo plugin] Saving matched execfiles:  
[JaCoCo plugin] Saving matched class directories for class-pattern: **/target/classes:
<<<<<<Classes folders list for all project>>>>>>>>
[JaCoCo plugin] Loading inclusions files..
[JaCoCo plugin] inclusions: []
[JaCoCo plugin] exclusions: []
[JaCoCo plugin] Thresholds: JacocoHealthReportThresholds [minClass=0, maxClass=0, minMethod=0, maxMethod=0, minLine=0, maxLine=0, minBranch=0, maxBranch=0, minInstruction=0, maxInstruction=0, minComplexity=0, maxComplexity=0]
[JaCoCo plugin] Publishing the results..
[JaCoCo plugin] Loading packages..
[JaCoCo plugin] Done.
[JaCoCo plugin] Overall coverage: class: 0, method: 0, line: 0, branch: 0, instruction: 0
Finished: SUCCESS

以下是我的jenkins针对jacoco报告的设置:

这是我的目标目录的文件夹结构。

目标目录位于项目目录下。

所以我真正关心的是为什么jenkins上的这些文件(即覆盖率文件)不能正确生成,而本地系统中的同一个命令生成正确的覆盖率报告。

谢谢。

P. S.:-我在多模块环境中这样做,我的源文件存在于一个项目中,测试文件存在于另一个项目中。因此,对于每个源项目,都存在一个测试项目。还有一件事,我刚刚注意到,在运行maven命令后,Class文件 /target/classes源代码目录下创建,而报告的html文件是在测试项目 /target/site目录下生成的。我不知道这是为什么。

共有1个答案

东门清夷
2023-03-14

我找到了我遗漏的代码,因为jenkins没有生成报告。

我忘记在jacocomaven插件中添加

:-)

 类似资料:
  • 问题内容: 从不同的代码库执行业务测试时,我必须获得应用程序的代码覆盖率。 我使用:Maven作为我的构建Jbehave作为我的测试框架。测试是用Java编写的。 我的应用程序是部署在tomcat上的一组war文件。 应用程序代码库与测试代码库是分开的。 为了获得覆盖范围,我遵循以下步骤。 1使用maven编译测试代码。 2将应用程序类从其构建位置($ {app.code.dir} / targe

  • 我看到詹金斯插件中的代码覆盖率为零。我在客户端服务器模式下使用 Jacoco 0.8.7。客户端是詹金斯,服务器(此处存在jaco代理jar)是一个VM。当我使用旧版本的jaco 0.7.4时,这并没有发生。 Jenkins CI日志- Jenkins CI插件配置是这样的。使用ant和maven组合来转储exec文件。

  • 我在声纳中的代码覆盖率显示为0%,这不是真的,因为我有单元测试。 格拉德尔 当我打开inside然后我可以看到成功的单元测试。 我在Jenkins环境中运行作为

  • 我的代码运行在具有单独JVM的单独虚拟机上。我想在此虚拟机上以tcpserver模式设置JaCoCo代理以收集覆盖率数据。然后,我将在我的maven项目中以tcpclient模式设置JaCoCo代理,以连接到上面提到的VM并获取覆盖率数据。 问题是代理不收集任何覆盖数据。在中创建了覆盖率数据文件,但该文件为空。 下面是代理选项:-Java agent:/usr/xx/plugins/org . j