当前位置:网站首页>Code coverage statistical artifact -jacobo tool practice
Code coverage statistical artifact -jacobo tool practice
2022-07-27 15:07:00 【Code classmate software test】
Code coverage ( English :Code coverage) It's a measure in software testing , Describe the proportion and degree of source code being tested in the program , The resulting ratio is called code coverage .
Test coverage
Test coverage is a measure of test completeness . Test coverage is the representation result of the coverage of test requirements and test cases or the coverage of executed code . On the one hand, it can measure the effectiveness of the test itself , Improve test efficiency , On the one hand, it can improve the quality of code , Reduce bug, Improve product reliability , stability .
The meaning of code coverage
· Analyze uncovered code , So as to deduce 3 Test whether the design is sufficient in the early stage , Whether the code not covered is the blind spot of test design , Why not consider ? demand / The design is not clear enough , Wrong understanding of test design , Strategic abandonment caused by the application of engineering methods, etc , After that, the supplementary test case design is carried out .
· Waste code detected in the program , You can reverse the confusion in code design , Reminder design / Developers sort out the logic of the code , Improve code quality .
· High code coverage does not mean high code quality , But on the other hand , Low code coverage , The code quality will not be much higher , It can be used as one of the important tools to test self-examination .
JaCoCo It's a free Java Code coverage library tools , from EclEmma Based on years of experience in using and integrating existing libraries, the team created , Its official website address is https://www.eclemma.org/jacoco/. Regardless of development and testing, there will be unit test cases written for yourself , Statistics on the number of business codes covered , Another appeal is that the statistical results can be generated automatically HTML The report , Now I'll pass maven、junit、jacoco To realize the above two demands .
The first thing you need to do is maven Of pom Add the following to the configuration file 3 A plug-in :
maven-surefire-plugin、jacoco-maven-plugin、maven-compiler-plugin.
this 3 The corresponding functions of the plug-ins are :
maven-surefire-plugin This plug-in is to execute junit、testng The framework is used for unit test cases ;
jacoco-maven-plugin This plug-in is used to calculate the coverage of business code by unit test cases ;
maven-compiler-plugin This plug-in is configured according to its jdk Version to compile java Source code used in .
following 3 This screenshot is the specific configuration content , You can also update and replace the version number according to the latest version .

Next, you need to write unit test cases for business code , Corresponding to the following two screenshots ,


It should be noted that , The package name of the test case should be consistent with that of the business code , otherwise JaCoCo Cannot count coverage .
Then perform the following 3 strip maven Command to clear 、 Plug in installation 、 test



And then in target\site\jacoco The report of this round of unit test results can be seen in the directory HTML Format results .

open JaCoCo Of html The format of the report is as follows , Statistics of overall coverage information , Click the package name link , You can see the details of Statistics .

It is worth noting that App There are only... In this business code class 1 individual main Method , But the number of statistical methods is 2 individual ,

Is this statistic inaccurate ? Statistics are accurate ,App There is also a default constructor in this class , Although not shown , How to prove that another 1 The first method is the constructor ? We can do it in App The test class AppTest Add test cases for constructors in , The details are shown in the following screenshot .

Unit test again , Generated JaCoCo The single test coverage report is as follows ,Missed The missing number is determined by the previous 2 A into 0 individual . prove JaCoCo The automatically generated default constructor is covered in the statistical method .Cov. This column is used to count the overall coverage of unit test cases of the specified business ; and Missed Branches Cov. This column is for the coverage of business code branches covered by unit test cases with branches , If a business class Missed Branches Cov. Branch coverage is n/a It indicates that there are no branches in this business class , Will appear n/a This is the result , In the screenshot below App、CoCo There is no branch code in these two business classes , therefore Missed Branches Cov. The statistical result of coverage is n/a, It can be understood that these two business classes do not need to count branch coverage ; Other columns , Coverage statistics that are not the focus of attention in the actual work process .

边栏推荐
- 资本频频加码,急于上市的和府捞面有多“疯狂”?
- 【云享读书会第13期】多媒体处理工具 FFmpeg 工具集
- DirectX 入门知识
- Toward fast, flexible, and robust low light image enhancement cvpr2022
- Basic exercises of C language
- TXT把换行 替换为空格或者取消换行
- 【云享读书会第13期】视频文件的封装格式
- Visual system design example (Halcon WinForm) -10. PLC communication
- How to help enterprises optimize office management
- Research on Chinese idiom metaphorical knowledge recognition and relevance based on transfer learning and text enhancement
猜你喜欢

Jmeter录制接口自动化

Annual comprehensive analysis of China's online video market in 2022

电子制造行业的数字化转型突破点在哪?精益制造是关键

JUC(JMM、Volatile)

MySQL 面试40连问,面试官你再问下去我可要翻脸了

Passive income: return to the original and safe two ways to earn

软件产品第三方测试费用为什么没有统一的报价?

Kubernetes CNI 分类/运行机制

代码覆盖率统计神器-jacoco工具实战

Graphic SQL of giant image
随机推荐
炒黄金开户平台有没有正规,安全的
【医疗行业】DICOM converter Tools
Differences among CPU, GPU and NPU
动态规划——股票买卖5
软件产品第三方测试费用为什么没有统一的报价?
What is tor? What is the use of tor browser update?
STM32F103C8T6在Arduino框架下驱动SH1106 1.3“ IIC OLED显示
网络设备硬核技术内幕 路由器篇 17 DPDK及其前传(二)
Confirm the time accuracy of the power supply setting voltage through the i/o function of vn1630/vn7640
Is there a regular and safe account opening platform for gold speculation
网络设备硬核技术内幕 路由器篇 10 CISCO ASR9900拆解 (三)
cap理论和base理论
UnityUI方面处理(归纳与积累)
这年头谁还不会抓包,WireShark 抓包及常用协议分析送给你!
于不确定中见“安全感” 沃尔沃2022年中问道
视觉系统设计实例(halcon-winform)-10.PLC通讯
Toward fast, flexible, and robust low light image enhancement cvpr2022
Why is there no unified quotation for third-party testing fees of software products?
网络设备硬核技术内幕 路由器篇 21 可重构的路由器
仅做两项修改,苹果就让StyleGANv2获得了3D生成能力