JaCoCo不基于源文件生成覆盖率报告-方法名称不可单击 [英] JaCoCo Not Generating Coverage Reports based on Source File - Method names not clickable

查看:258
本文介绍了JaCoCo不基于源文件生成覆盖率报告-方法名称不可单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven多模块项目,其中JaCoCo不会基于源文件生成报告.

I have a Maven multi module project where the JaCoCo is not generating reports based on the source files.

通常,如果 MyService 是受测试的类,则将通过两种方式进行报告,一种是通过文件名 MyService.html 在基于程序包的适当位置,并带有一个方法列表,以数字和图形的形式全面显示覆盖范围-列出该类中的所有方法,每个方法都有可点击的链接,该链接指向包含源代码的另一个html MyService.java.html 红色/绿色/黄色背景的代码以显示覆盖状态.

Generally, if MyService is the class under test, it would be reported in two ways, one through a file name MyService.html in appropriate package based location with a list of methods giving an overall picture of the coverage in numbers and graphs - with listing of all the methods in the class and each method has a clickable link to another html MyService.java.html which contains the source code with red/green/yellow background to display coverage status.

在我的方案中,仅生成 MyService.html ,而没有列出 MyService.java.html 和方法,其中包含覆盖率详细信息,但没有指向以下内容的超链接另一个报告如下所示.

In my scenario, only MyService.html is generated and not the MyService.java.html and methods are listed in the former with coverage details, but without hyperlinks to the other report as displayed below.

问题在这里变得更加有趣,因为我的Maven配置未在此模块中配置,但是在父模块和其他子模块中能够正确生成报告.以下是Maven插件配置,以供参考.

Issue gets more interesting here that my Maven configuration is not configured in this module, but in a parent module and other child modules are able to generate reports properly. Below is the maven plugin configuration for reference.

父POM:

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>${jacoco.version}</version>
  <configuration>
     <destFile>${project.basedir}/target/jacoco-unit.exec</destFile>
     <dataFile>${project.basedir}/target/jacoco-unit.exec</dataFile>
     <append>true</append>
  </configuration>
  <executions>
     <execution>
        <id>jacoco-initialize</id>
        <goals>
           <goal>prepare-agent</goal>
        </goals>
     </execution>
     <execution>
        <id>jacoco-site</id>
        <phase>package</phase>
        <goals>
           <goal>report</goal>
        </goals>
     </execution>
  </executions>
</plugin>

儿童POM:

    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
    </plugin>

尝试切换JaCoCo版本,但无济于事,现在坚持使用最新的0.8.2.而Maven是最新的-3.6.0.除此之外,子pom中配置的另一个插件是PMD-其存在与否对报告没有任何影响.

Tried switching JaCoCo versions, but none helped, now sticking to the latest 0.8.2. And Maven is latest - 3.6.0. Apart from this, the other plugin configured in the child pom is PMD - whose presence or absence did not make any difference to report.

类似的问题: Gradle JaCoCo插件-报告中不可单击的类和方法名称

推荐答案

在没有最小,完整和可验证的示例的情况下,完全演示了重现您难度的步骤,只能引用 JaCoCo常见问题解答:

In absence of Minimal, Complete, and Verifiable example that fully demonstrates steps to reproduce your difficulty, can only quote JaCoCo FAQ :

覆盖率报告为什么不显示突出显示的源代码?

确保满足以下先决条件才能获取源代码在JaCoCo覆盖率报告中突出显示:

Why does the coverage report not show highlighted source code?

Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports:

  • 类文件必须使用调试信息进行编译才能包含行数字.
  • 在生成报告时必须正确提供源文件时间.

关于第一点,请参见 javac -g 选项,

About first point see -g option of javac, debug and debuglevel options of maven-compiler-plugin.

第二点,请确保源文件 Example.java

For the second point make sure that source file Example.java with

package org.example;

位于 src/main/java/org/example/Example.java

这篇关于JaCoCo不基于源文件生成覆盖率报告-方法名称不可单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆