当前位置:网站首页>Jacobo code coverage
Jacobo code coverage
2022-07-07 15:22:00 【Proud cat sauce】
Original address :
jacoco Instructions for incremental solutions _dray_ The blog of -CSDN Blog _jacoco The incremental
jacoco: jacoco Second opening , Support incremental code coverage
One 、Jacoco brief introduction :
JaCoCo It's an open source Java Code coverage tools .
JaCoCo Only the coverage of full code is counted , During code iteration , For example, it was modified bug, Another version of the code has been released .JaCoCo The statistics of are cleared , Trigger code coverage needs to be performed from scratch .
This scenario , We just need to test the incremental code , It's time to be right about jacoco Secondary development .
jacoco Count code coverage , Generally, it is combined with automation , such as jacoco Combined with interface automation . At that time, we can also perform it manually case, To count code coverage .
Can be embedded into Ant、Maven in ; It can be used as Eclipse plug-in unit , You can use it JavaAgent Technical monitoring Java Procedures, etc .
Many third-party tools provide access to JaCoCo Integration of , Such as sonar、Jenkins etc. .
Two 、 Code coverage introduction :
Coverage is used to measure the test of test code to function code . Through statistics, test the lines in the function code 、 Branch 、 Class and other simulation scenarios , To quantify the adequacy of the test .
Code coverage = Code coverage , A measure .
Coverage is simple : Ran a test case , Those modules in the project code 、 file 、 class 、 Method Yes .
The row coverage is the finest granularity , Other coverage rates can be calculated from the row coverage rate .
2.1 Line overlay
When at least one instruction is specified Source line Execution time , The source line is considered to have been executed .
Generally speaking, it means , Test behavior , Triggered this line of code , Then this line of code is covered .
2.2 Branch coverage
if and switch Statement counts as branch coverage , This indicator calculates the total number of branches in a method , And determine the number of branches executed and not executed .
All uncovered : All branches are not executed , Red sign
Partial coverage : Some branches are executed , Yellow sign
Full coverage : All branches have been executed , Green sign .
2.3 Methods cover
When at least one instruction in the method is executed , The method is considered to have been performed , Including constructors and static initialization methods .
2.4 Code coverage means
Analyze uncovered code , Whether the backstepping test design is sufficient , Whether there are test design blind spots in the code not covered .
2.5 Misunderstanding of coverage
If the code is as follows :
if (i>100)
j = 10/i // There is no division 0 error
else
j = 10/(i+2) // i==-2, except 0 error
Cover 2 Branches , Just design i==101 and i==1, But for finding i==-2 This bug There is no effect when clicking .
therefore :
1、 Don't simply pursue high code coverage
2、 High coverage test cases do not mean that test cases are valid
3、 A branch that is not covered is equivalent to any error on the branch that cannot be found
3、 ... and 、jacoco principle
jacoco Use the method of inserting piles to record the coverage data , Through a probe Probe to inject .
The pile insertion modes are 2 Kind of :
3.1 on-the-fly Pattern
7、Jacoco Incremental coverage
7.1 Incremental coverage
Incremental coverage : What code or branches are not covered between two submissions .
Purpose : Detect the line coverage of the same test case on the code before and after modification
Suppose that the code changes submitted twice are as follows :
if(x>100)
- print(1)
+ print(2)
else
- print(3)
+ print(4)
Each line of code has 3 States :+、-、 unchanged
Before and after modification , Run the same test case , Each row has 4 States : Overwrite before modification / Not overwritten before modification , Overwrite after modification / Modified but not overwritten .
So the incremental coverage has 3x4=12 In this case , More important are : The new code does not cover , The new code covers , Unchanged code is overwritten before modification , Not covered after modification .
7.2 Incremental Application
jacoco Second opening : https://gitee.com/Dray/jacoco.git
Incremental code acquisition : https://gitee.com/Dray/dode-diff.git
Usage method :
1、jacoco client , To collect information
边栏推荐
- MySQL bit type resolution
- Database exception resolution caused by large table delete data deletion
- CTFshow,信息搜集:web12
- Read PG in data warehouse in one article_ stat
- 连接ftp服务器教程
- Ctfshow, information collection: web13
- Unity之ASE实现全屏风沙效果
- Notes HCIA
- Discussion on CPU and chiplet Technology
- “百度杯”CTF比赛 2017 二月场,Web:include
猜你喜欢
CTFshow,信息搜集:web3
【跟着江科大学Stm32】STM32F103C8T6_PWM控制直流电机_代码
Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
【深度学习】语义分割实验:Unet网络/MSRC2数据集
CTFshow,信息搜集:web10
[understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper
【搞船日记】【Shapr3D的STL格式转Gcode】
【数字IC验证快速入门】29、SystemVerilog项目实践之AHB-SRAMC(9)(AHB-SRAMC SVTB Overview)
Summer safety is very important! Emergency safety education enters kindergarten
【数字IC验证快速入门】26、SystemVerilog项目实践之AHB-SRAMC(6)(APB协议基本要点)
随机推荐
【數字IC驗證快速入門】26、SystemVerilog項目實踐之AHB-SRAMC(6)(APB協議基本要點)
Ctfshow, information collection: web13
Summer safety is very important! Emergency safety education enters kindergarten
How does the database perform dynamic custom sorting?
最安全的证券交易app都有哪些
CTFshow,信息搜集:web13
Ctfshow, information collection: web7
Guangzhou Development Zone enables geographical indication products to help rural revitalization
CTFshow,信息搜集:web5
jacoco代码覆盖率
Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)
大表delete删数据导致数据库异常解决
[target detection] yolov5 Runtong voc2007 data set
Introduction of mongod management database method
JSON parsing instance (QT including source code)
Ctfshow, information collection: web4
MongoD管理数据库的方法介绍
Bits and Information & integer notes
Niuke real problem programming - Day9
Connecting FTP server tutorial