当前位置:网站首页>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
边栏推荐
- 【数字IC验证快速入门】23、SystemVerilog项目实践之AHB-SRAMC(3)(AHB协议基本要点)
- 2. Basic knowledge of golang
- 什么是pv和uv? pv、uv
- Ctfshow, information collection: web7
- Ctfshow, information collection: web4
- Ctfshow, information collection: web12
- Stream learning notes
- Unity's ASE realizes cartoon flame
- Write a ten thousand word long article "CAS spin lock" to send Jay's new album to the top of the hot list
- 银行需要搭建智能客服模块的中台能力,驱动全场景智能客服务升级
猜你喜欢
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
Niuke real problem programming - day18
Bye, Dachang! I'm going to the factory today
"Baidu Cup" CTF competition 2017 February, web:include
使用Scrapy框架爬取网页并保存到Mysql的实现
Niuke real problem programming - Day12
银行需要搭建智能客服模块的中台能力,驱动全场景智能客服务升级
Summer safety is very important! Emergency safety education enters kindergarten
[机缘参悟-40]:方向、规则、选择、努力、公平、认知、能力、行动,读3GPP 6G白皮书的五层感悟
Ctfshow, information collection: web2
随机推荐
Basic knowledge sorting of mongodb database
什麼是數據泄露
Ctfshow, information collection: web5
IDA pro逆向工具寻找socket server的IP和port
CTFshow,信息搜集:web7
buffer overflow protection
[data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering
大表delete删数据导致数据库异常解决
Integer learning
Compile advanced notes
Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)
“百度杯”CTF比赛 2017 二月场,Web:include
CTFshow,信息搜集:web10
Database exception resolution caused by large table delete data deletion
asp. Netnba information management system VS development SQLSERVER database web structure c programming computer web page source code project detailed design
【数字IC验证快速入门】29、SystemVerilog项目实践之AHB-SRAMC(9)(AHB-SRAMC SVTB Overview)
Ctfshow, information collection: web12
Niuke real problem programming - Day12
CTFshow,信息搜集:web12
【目标检测】YOLOv5跑通VOC2007数据集