问题标签 [jacoco-maven-plugin]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1435 浏览

java - Jacoco fails only on my system with strange error about StringUtils

Jacoco is giving me this error when trying to test my web service (I get it with any maven goal that includes the test phase):

Just to be clear, I am not using StringUtils anywhere in my code, not even in my test code. My project builds and runs fine without it, if tests are skipped.

I've googled maven issues, jacoco issues, surefire issues, and tried all solutions I came across.

Here is what I tried:

  • Clean build, also deleting the whole target directory manually
  • Adding several different dependencies containing StringUtils to the pom (including the original commons-lang-2.6.jar and the new commons-lang3 library)
  • Deleting my .m2/repository/org/apache/maven directory to redownload all repository libraries
  • Comparing with my other projects that use similar test cases to find any possible difference that might cause this
  • Using different versions of surefire, failsafe, and surefire-report plugins
  • Adding <skipTests>true</skipTests> to both surefire and failsafe plugin configurations in the pom (some similar issues I read happened because test cases were being run twice)
  • Excluding various output directories using <exclude> tag in jacoco plugin configuration
  • Altering the source and target JDK versions in the maven compiler plugin configuration
  • Inserting the StringUtils.class directly into the jacoco pom in the appropriate directory matching the missing class name and package
  • Using different versions of the jacoco plugin
  • Installing and using a different version of Maven (tried both 3.1.1 and 3.3.9)
  • Switching to cobertura (I get a very similar error that differs only in the class it says is missing - org/apache/commons/lang/SystemUtils, rather than StringUtils)

I've been pulling my hair out over this for a whole day. I was able to have someone else test it and it worked fine on their system. I then copied their target directory onto my machine and was able to execute Sonar code analysis against the successful build results (jacoco.exec and the checked in code).

My question is, what is messed up on my system that is causing this?

I am running Windows 7 64-bit on a HP EliteDesk. Here is my pom.xml:

My test cases aren't anything special, they basically just send a sample POST request to each of the endpoints and verify that a result comes back.

Here is an example test case:

I'll be happy to post any other settings or whatever you might want to know about my system.

UPDATE: I just found out about jHades which is a tool to help you identify conflicting Jar resources when you run into jar-hell scenarios like this. I haven't tried it yet, but I plan to and will update the results here if it produces anything.

0 投票
1 回答
979 浏览

java - Jacoco - 忽略 MyClass.1

Jacoco 覆盖范围内如何忽略 *.1 类?

我的 POM 中有以下内容:

但是,我收到以下错误消息:

[警告] com.mypackage.MyClass.1 类违反规则:行覆盖率为 0.00,但预期最小值为 0.85

更新 12/19

这是文件夹结构中的内容:

0 投票
1 回答
4520 浏览

java - 将多个测试运行合并到一个 Jacoco.exec 文件中

在我的基于环境变量的项目中,运行了不同的集成测试集。例如

运行两条线可以提供完整的测试覆盖率。

现在的问题是每次运行都会在目标文件夹中创建一个 jacoco.exec 文件,但是第二次运行会通过删除目标文件夹来覆盖第一次运行。

我想使用 jacoco merge 来合并 exec 文件,但我不知道该怎么做。

我可以将输出目录更改为目标和合并以外的其他位置,但是我将如何维护版本,或者我必须在合并完成后添加一行来删除文件夹。

任何帮助,将不胜感激

0 投票
1 回答
1391 浏览

java - 执行 jacoco 准备代理时,使用反射捕获 Java 注释将不起作用

我有一个多模块 Maven 项目。这有一组由 jaxb 使用 xsd 生成的类。下面给出了此类的示例。(没有 getter 和 setter)

一个模块需要它们作为键值对。因此,一种使用反射编写的方法将它们转换为键值对列表。在该字段的名称用作键和值作为其值。采取如下方式。

有一些测试用例使用了这种转换。它们工作正常并使用 Maven 构建执行。为了获取代码覆盖率,添加了 jacoco-maven-plugin。运行时它不会生成 jacoco.exec 文件。根据this post执行目标被添加到我的pom文件中。之后我的单元测试失败,给出一个空指针异常。根据堆栈跟踪,它是在执行“xmlElement.name()”时引起的,这意味着 xmlElement 为空。因此,添加此执行目标后,反射无法获得注释。

我如何解决这个问题并使用 jacoco 或任何其他方式获取代码覆盖率报告。

提前致谢。

0 投票
3 回答
7763 浏览

jenkins - Jacoco 代码覆盖率显示 Jenkins 的覆盖率为 0%

我已经阅读了大多数类似问题的答案,但没有一个适合回答我的问题。

我在 pom 文件中的配置文件如下所示:

当我以 Maven 目标运行我的詹金斯工作时clean install -P test-coverage

我在我的 Jenkins 日志中看到了这一点:

这就是我为 Jacoco 配置的 Jenkins 的样子:

在此处输入图像描述

0 投票
1 回答
1606 浏览

java - JaCoCo 插件提供不同的覆盖范围

我正在使用 JaCoCo Maven 插件和代理来测量和检索每晚测试的应用程序的代码覆盖率数据。这是架构的架构:

测试架构

我的 Maven 项目配置了JMeter Maven 插件verify,以便在 Maven阶段执行一些 API 测试。Jenkins服务器执行的Maven命令如下

正如您所看到的,首先测试通过verify阶段执行,然后jacoco:dump目标从测试服务器检索覆盖率数据(我将服务器配置为运行 JaCoCo 代理),最后将数据上传到我的 Sonar 服务器。

我遇到的“奇怪”行为是,如果我在我的计算机上运行此命令,然后在 SonarQube 页面中的 Jenkins(相应地配置 Jenkins 项目)上运行,我会得到不同的覆盖结果。此外,如果我配置 Jenkins 项目,然后简单地复制它,创建一个新的(但等效的)Jenkins 项目,结果会有所不同。

本地测试覆盖结果

Jenkins 的覆盖结果

我尝试了不同的配置和案例,但我无法理解问题所在。我是否没有考虑一些 JaCoCo 约束(例如与 Jenkins 项目名称相关的某些东西)?

0 投票
2 回答
414 浏览

unit-testing - Jacoco 是否记录单元测试持续时间?

您可以使用Jacoco代理运行JUnit测试以生成出色的覆盖率报告。(它在单元测试的运行过程中产生一个不透明的文件)。*.exec

一些工具,如Sonar - 读取*.exec文件并收集数据以生成报告。声纳能够告诉单元测试持续时间 - 但我不确定它是否从这个*.exec文件中得到它。

我的问题是:Jacoco 是否记录单元测试持续时间?(无论它是否在其生成的报告中显示)。

0 投票
1 回答
496 浏览

java - jacoco maven 插件可以从文件中读取排除项吗?

您可以使用Jacoco代理运行JUnit测试以生成出色的覆盖率报告。(它在单元测试的运行过程中产生一个不透明的文件)。*.exec

现在,surefire有一个参数可以从文件中加载排除项。

Maven 可以读取属性列表。它可能能够将变量读入列表。

我的问题是:jacoco maven 插件可以从文件中读取排除项吗?

0 投票
0 回答
125 浏览

maven - 如果未在 SonarQube 中计算,则保留代码覆盖率统计信息

在我的应用程序的构建过程中,我使用 SonarQube 来显示一些关于代码质量的统计数据。特别是我们用它来显示一些每晚执行的测试的代码覆盖率。

为了计算和检索代码覆盖率数据,我以这种方式使用 JaCoCo Maven 插件和代理:

以这种方式计算的代码覆盖率是正确的(因为它反映了某些每晚执行的测试的预期覆盖率)。

但在某些情况下,我无法执行jacoco:dump检索代码覆盖率统计的目标。在这些情况下,执行sonar:sonar会将现有代码覆盖率统计信息(根据jacoco:dump目标的先前执行计算)为 0,因为 Sonar 假设如果未发送统计信息,则该统计信息不存在。

我想做的是,如果我不这样做dump并使用 JaCoCo 计算代码覆盖率指数,SonarQube 中的代码覆盖率测量值不会丢失,而是等于最后计算的值。

有什么方法可以指示 SonarQube 服务器或 Maven Sonar 插件保留过去的代码覆盖率统计信息?

0 投票
2 回答
22929 浏览

java - 如何使用 JaCoCo maven 插件排除 SonarQube 的代码覆盖率文件

我在集成 JaCoCo maven 插件以覆盖 SonarQube 6.0 的代码时遇到了一个大问题。

我有一个多模块 Maven 项目让我们说:

在主 pom.xml 中,我设置了这样的报告配置文件:

在孩子们中,我通过添加一些排除来重载配置:

这里的想法是删除代码覆盖率的 Pojo(我们也为其他类型的 Class 这样做......)

当我运行 mvn 命令行时:

我所有的报告都生成得很好,但在声纳中,没有考虑到排除...

请你能帮我解决这个问题吗?