Skipping JaCoCo execution due to missing execution data file
# 情境分析
今天在为项目集成sonar单元测试覆盖率的过程中,发现了许多问题,在这里记录下,为大家提供一下解决思路# 单测覆盖率执行思路
1. 首先通过maven打包,然后生成测试文件
2. sonar扫描导入maven生成的测试文件,出现单测覆盖率# 可能出现问题的点
1. 可能没有生成测试文件
2. 生成的测试文件可能为空,没有数据# 上面两个问题,如何确定呢? (通过查看日志)
1. 使用 Surefire 配置破坏 JaCoCo 代理
在maven install打包的日志中,出现如下日志信息
[INFO] Skipping JaCoCo execution due to missing execution data file.或者,不会出现如下信息[INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (default-prepare-agent) @ sirius ---
[INFO] surefireArgLine set to -javaagent:/builds/situ/situ-java-program/situ-galaxy/sir-server/sir/./.m2/repository/org/jacoco/org.jacoco.agent/0.8.5/org.jacoco.agent-0.8.5-runtime.jar=destfile=/builds/situ/situ-java-program/situ-galaxy/sir-server/sir/target/jacoco.exec,includes=com/situ/sir/**/*,excludes=**/po/**/*:**/config/**/*2. 虽然单个测试类可以运行也没有错,但是maven install打包的时候,run的数字为0
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
# pom文件示例配置 (第一种)<properties><!-- sonar单测扫描 --><jacoco.version>0.8.5</jacoco.version><jacoco.reportPath>${project.basedir}/target/jacoco-ut.exec</jacoco.reportPath>
</properties><dependency><groupId>org.jacoco</groupId><artifactId>org.jacoco.agent</artifactId><version>${jacoco.version}</version><classifier>runtime</classifier>
</dependency><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.22.2</version><configuration><systemPropertyVariables><jacoco-agent.destfile>${jacoco.reportPath}</jacoco-agent.destfile></systemPropertyVariables></configuration></plugin><plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>${jacoco.version}</version><configuration><includes> <!--覆盖率计算包含的类--><include>com/cc/situ/**/*</include></includes><excludes><exclude>**/po/**/*</exclude><exclude>**/config/**/*</exclude></excludes></configuration><executions><execution><id>report</id><phase>prepare-package</phase><goals><goal>report</goal><!--生成覆盖率文件和报告--></goals><configuration><dataFile>${jacoco.reportPath}</dataFile></configuration></execution></executions>
</plugin>
如果你按照第一种不行,在日志中出现错误情况的第一种
那么可能是Surefire 配置破坏 JaCoCo 代理
请采用第二种方案
# pom文件示例配置 (第二种)<properties><!-- sonar单测扫描 --><jacoco.version>0.8.5</jacoco.version><jacoco.reportPath>${project.basedir}/target/jacoco-ut.exec</jacoco.reportPath>
</properties><dependency><groupId>org.jacoco</groupId><artifactId>org.jacoco.agent</artifactId><version>${jacoco.version}</version><classifier>runtime</classifier>
</dependency><plugins><plugin><groupId>org.jacoco</groupId><artifactId>jacoco-maven-plugin</artifactId><version>${jacoco.version}</version><configuration><includes> <!--覆盖率计算包含的类--><include>com/situation/sirius/**/*</include></includes><excludes> <!--排除像Pojo、配置等无单元测试意义的类。如有,在Sonar服务端也需要配合排除(Ignore Code Coverage: https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/#header-5)--><exclude>**/po/**/*</exclude><exclude>**/config/**/*</exclude></excludes></configuration><executions><execution><id>default-prepare-agent</id><goals><goal>prepare-agent</goal></goals><configuration><propertyName>surefireArgLine</propertyName></configuration></execution><execution><id>report</id><phase>prepare-package</phase><goals><goal>report</goal><!--生成覆盖率文件和报告--></goals><configuration><dataFile>${jacoco.reportPath}</dataFile></configuration></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.22.2</version><configuration><useSystemClassLoader>false</useSystemClassLoader><forkMode>once</forkMode><reuseForks>true</reuseForks><testFailureIgnore>true</testFailureIgnore><!--suppress UnresolvedMavenProperty --><argLine>-Dfile.encoding=UTF-8 ${surefireArgLine}</argLine><systemPropertyVariables><jacoco-agent.destfile>${jacoco.reportPath}</jacoco-agent.destfile></systemPropertyVariables></configuration></plugin>
</plugins>
请注意maven依赖也会影响,是否能够检测出单测覆盖率
# 请使用第一个,不要使用第二个1. 第一个
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><version>${springboot.version}</version>
</dependency>2. 第二个
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-test</artifactId><version>${springboot.version}</version>
</dependency>
Skipping JaCoCo execution due to missing execution data file相关推荐
- reposync提示Removing *.rpm, due to missing GPG key
执行完 reposync 同步rhel-7-server-rpms仓库的命令之后,出现如下提示,并删除了同步到本地的软件包. Removing kernel-debug-3.10.0-1062.1.1 ...
- No execution.target specified in your configuration file.
完整报错如下: Exception in thread "main" java.lang.NullPointerException: No execution.target spe ...
- 如何处理错误消息Unable to install breakpoint due to missing line number attributes
Created by Wang, Jerry, last modified on Mar 11, 2017 Unable to install breakpoint due to missing li ...
- Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean 解决方案
SpringBoot启动时的异常信息 "C:\Program Files\Java\jdk1.8.0_161\bin\java" ......... com.fangxing.ja ...
- Unable to install breakpoint in XXX due to missing line number attributes的解决
Eclipse下Debug时弹出错误"Unable to install breakpoint due to missing line number attributes,Modify co ...
- 创建vue项目的时候报错:Skipped git commit due to missing username and email in git config.
创建vue项目的时候报错: WARN Skipped git commit due to missing username and email in git config, or failed to ...
- 导入数据库显示服务器发生意外,mysql 数据库无法启动(Ignoring the redo log due to missing M...
mysql 数据库无法启动(Ignoring the redo log due to missing M mysql 数据库无法启动(Ignoring the redo log due to miss ...
- .\Fire_FreeRTOS.axf: Error: L6221E: Execution region ER_RO with Execution range [0x00000000,0x000001
.\Fire_FreeRTOS.axf: Error: L6221E: Execution region ER_RO with Execution range [0x00000000,0x000001 ...
- when you start Windows 7: The Windows Boot Configuration Data file is missing required information
When you start Windows 7, you receive the following error message: File: \Boot\BCD Status: 0xc000003 ...
- Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing Embedd
spring boot启动时报错: Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing Embedded ...
最新文章
- 给插店一个成功案例给自己一次机会
- 【codeforces 507E】Breaking Good
- Linux如何切换图形界面和命令行界面
- sqoop遇到的问题
- 【答题卡识别】基于matlab GUI hough变换答题卡判定与成绩统计【含Matlab源码 752期】
- Java基础题练习(switch多选择结构的使用、white循环中++的使用、white循环中输入分数游戏)
- vue启动时git dep preparation failed 报错
- 优锘科技:物联森友会发布助物联网企业加速成长
- Gym - 100781A Adjoin the Networks (树的直径)
- Flutter之Pigeon插件与Android通信使用指南
- 卢卡斯定理求组合数(逆元+费马小定理+扩展欧几里得)
- 数字语言,简历的“含金量”
- 汽车之外 这届2018CES盛会电视和语音助理也很亮眼 | CES
- APPLE G5 机箱改造“黑苹果”全攻略
- 第059篇:高分二号遥感影像预处理流程(ENVI5.3.1平台+ENVI App Store中最新的中国国产卫星支持工具)
- [笔记]Windows核心编程《二十》DLL的高级操作技术
- 数据湖和数据仓库区别介绍
- OpenCV图片拼接
- Android - 简单的显示高德SDK中的3D地图
- oj. 1008——最长公共子序列
热门文章
- 百度云apkg手机文件怎么打开_无需会员 | 手机免费解压百度云压缩文件
- 图层重命名快捷键_ps怎么给图层(批量)重命名的方法
- 三种百度网盘加速器,轻松突破10M/S,总有一款适合你!
- 语音转文字的测试用例
- UVALive7461 - Separating Pebbles 判断两个凸包相交
- 智能车室内光电组ROS-2020—— 创建工作空间以及移植比赛模型文件
- 微信小程序云数据库操作
- 谷歌插件文档 镜像_最好的Google文档插件
- JAVA怎么打开pkg_PKG文件在电脑上怎么打开!(普通PC)
- 信号转换 | 如何将正弦波转换成方波?