当前位置:网站首页>jacoco代码覆盖率
jacoco代码覆盖率
2022-07-07 13:17:00 【傲娇的喵酱】
原文地址:
jacoco 增量方案使用说明书_dray_的博客-CSDN博客_jacoco 增量
一、Jacoco简介:
JaCoCo是一个开源的Java代码覆盖率工具。
JaCoCo 只是统计了全量代码的覆盖率,在代码迭代过程中,比如修改了bug,又重新发布了一版代码。JaCoCo 的统计就被清空了,需要从头执行触发代码覆盖。
这种场景,我们只需要测试增量代码就可以了,这个时候需要对jacoco进行二次开发。
jacoco 统计代码覆盖率,一般与自动化相结合,比如jacoco与接口自动化相结合。当时我们也可以手工执行case,来统计代码覆盖率。
可以嵌入到Ant、Maven中;可以作为Eclipse插件,可以使用其JavaAgent技术监控Java程序等等。
很多第三方的工具提供了对JaCoCo的集成,如sonar、Jenkins等。
二、代码覆盖率介绍:
覆盖率是用来衡量测试代码对功能代码的测试情况。通过统计测试代码中对功能代码中行、分支、类等模拟场景数量,来量化说明测试的充分度。
代码覆盖率=代码的覆盖程度,一种度量方式。
覆盖率简单说:跑了一个测试用例,项目代码中的那些模块、文件、类、方法 执行了。
其中行覆盖率是最细颗粒度,其他覆盖率都可从行覆盖率情况统计算出来。
2.1 行覆盖
当至少一个指令被指定源码行执行时,该源码行被认为已执行。
通俗的说就是,测试行为,触发了这某一行代码,则这一行代码就被覆盖了。
2.2 分支覆盖
if 和switch 语句算作分支覆盖率,这个指标计算一个方法中的分支总数,并决定已执行和未执行的分支的数量。
全部未覆盖:所有分支均未执行,红色标志
部分覆盖:部分分支被执行,黄色标志
全覆盖:所有分支均已执行,绿色标志。
2.3 方法覆盖
当方法中至少有一个指令被执行,该方法被认为已执行,包括构造函数和静态初始化方法。
2.4 代码覆盖率意义
分析未覆盖部分的代码,反推测试设计是否充分,没有覆盖到的代码是否存在测试设计盲点。
2.5 覆盖率的误区
若代码如下:
if (i>100)
j = 10/i // 没有除0错误
else
j = 10/(i+2) // i==-2,除0错误覆盖2个分支,只需要设计i==101 和 i==1,但是对于找到i==-2这个bug点时没有作用的。
所以:
1、不要简单的追求高的代码覆盖率
2、高覆盖率测试用例不等于测试用例有效
3、没覆盖的分支相当于该分支上的任何错误肯定都找不到
三、jacoco原理
jacoco使用插桩的方式来记录覆盖率数据,是通过一个probe探针来注入。
插桩模式有2种:
3.1 on-the-fly模式
7、Jacoco增量覆盖
7.1 增量覆盖
增量覆盖:两次提交之间有哪些代码或者分支没有被覆盖。
目的:检测同一个测试用例在修改前后代码上的行覆盖情况
假设两次提交代码变更如下:
if(x>100)
- print(1)
+ print(2)
else
- print(3)
+ print(4)
每行代码有3种状态:+、-、不变
修改前后,跑同一个测试用例,每行有4种状态:修改前覆盖/修改前未覆盖,修改后覆盖/修改后未覆盖。
所以增量覆盖总共有3x4=12种情况,比较重要的有:新增代码没有覆盖,新增代码覆盖了,不变的代码修改前覆盖,修改后未覆盖等等。
7.2 增量应用
jacoco 二开: https://gitee.com/Dray/jacoco.git
增量代码获取: https://gitee.com/Dray/dode-diff.git
使用方法:
1、jacoco客户端,收集信息
边栏推荐
- TypeScript 发布 4.8 beta 版本
- Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
- 【OBS】RTMPSockBuf_ Fill, remote host closed connection.
- Why do we use UTF-8 encoding?
- PAT 甲级 1103 Integer Factorizatio
- Read PG in data warehouse in one article_ stat
- Spatiotemporal deformable convolution for compressed video quality enhancement (STDF)
- Novel Slot Detection: A Benchmark for Discovering Unknown Slot Types in the Dialogue System
- Ctfshow, information collection: web12
- Qu'est - ce qu'une violation de données
猜你喜欢

Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)

Discussion on CPU and chiplet Technology

简述keepalived工作原理
![[understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper](/img/38/cc5bb5eaa3dcee5ae2d51a904cf26a.png)
[understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper

Bye, Dachang! I'm going to the factory today

CTFshow,信息搜集:web6

#HPDC智能基座人才发展峰会随笔
![[target detection] yolov5 Runtong voc2007 data set](/img/b3/b7f3d46075cb1782d772a24362003e.png)
[target detection] yolov5 Runtong voc2007 data set

With 8 modules and 40 thinking models, you can break the shackles of thinking and meet the thinking needs of different stages and scenes of your work. Collect it quickly and learn it slowly

CPU与chiplet技术杂谈
随机推荐
CTFshow,信息搜集:web13
@Introduction and three usages of controlleradvice
Compile advanced notes
Summer safety is very important! Emergency safety education enters kindergarten
写一篇万字长文《CAS自旋锁》送杰伦的新专辑登顶热榜
How does the database perform dynamic custom sorting?
【兰州大学】考研初试复试资料分享
Several ways of JS jump link
Lidar Knowledge Drop
【OBS】RTMPSockBuf_Fill, remote host closed connection.
Today's sleep quality record 78 points
Niuke real problem programming - Day17
Xiaomi's path of chip self-development
Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched
CTFshow,信息搜集:web6
避坑:Sql中 in 和not in中有null值的情况说明
Mathematical modeling -- what is mathematical modeling
上半年晋升 P8 成功,还买了别墅!
MySQL installation configuration 2021 in Windows Environment
什么是pv和uv? pv、uv