当前位置:网站首页>Advanced skills of testers: a guide to the application of unit test reports
Advanced skills of testers: a guide to the application of unit test reports
2022-06-30 19:36:00 【Little brother said test】
Why unit testing is needed
From a product perspective , Routine function test 、 System tests are conducted based on the local or global functions of the product , It can be well combined with the needs of users , But there is a lack of product development details ( Especially the understanding of code details ).
From the tester's point of view , Functional test, system test and other performance tests require testers to have a high ability to understand the global characteristics , As long as testers can master oneortwo automated test frameworks, they can basically carry out functions 、 Performance automated testing , But research and development with the help of test framework reduces the mastery of testers 、 Understanding requirements .
From a developer perspective , User requirements are often not specific 、 comprehensive , Therefore, there are limitations in converting user requirements into development documents or writing development code for a certain function ( That is what we often say bug).
therefore , Writing unit tests can help testers better understand code details 、 Improve code development capability , It can also help developers identify possible problems in the code in advance bug, Improve the fault tolerance of code .
How to make unit test report
Good unit test reports can help testers better analyze 、 Digging for hidden problems . that , How to make a unit test report , From which dimensions ? Here we mainly think about this problem from the perspective of testers .
First , We need to present the number of our test cases and test results in the report (pass perhaps fail), And error details .
secondly , Starting from the characteristics of unit test itself , We need to be able to show the branch for unit code in the report 、 Coverage of unit methods, etc , Better help us sort out and test the excellence of case design .
Here it is , We use surefire-report Count the number of test cases and test results , Use jacoco The coverage rate of unit measurement is calculated ( notes : The default test case execution method in this article is mvn test).
How to configure
surefire-report To configure
Configuration method : To configure maven-surefire-plugin plug-in unit ,maven-surefire-plugin yes maven default test actuator , The configuration method is shown in the figure below :

Above picture testFailureIgnore It means to ignore the errors in the unit test and continue to build ,**/*Test.java: Indicates that all the names under any subdirectory are named with Test At the end of the Java class ,**/Test*.java: It means that all naming under any subdirectory will not be executed Test At the beginning Java class .
Execution method : Use mvn test surefire-report:report that will do , Will be generated in /target/site/surefire-report.html Test report document .
As shown in the figure below :
Tests Displays the total number of use cases ;
Errors It refers to the situation that the procedure does not take into account , For example, exception failed to catch ;
Failure It refers to the difference between the expected result and the result of the actual operation unit , It often appears in assertions ;
Skipped Indicates the number of test cases skipped ;
Success Rate Indicates the success rate of the use case (= Number of successful use cases / Total number of use cases );
Time Show total time ;
Package List Show detailed package Next use case execution result .

jacoco To configure
Configuration method : To configure jacoco-maven-plugin plug-in unit , The configuration method is shown in the figure below ,phase Represents the life cycle phase of the plug-in operation .

Execution method :mvn test Execution can be . Will be in /target/site/jacoco/ Generate the total coverage report under the directory index.html And different package Unit test coverage report for ../xxx/index.html. Besides, there are csv and xml Unit test coverage report in .

As shown in the above figure, there is a package Unit test coverage report for :
The red progress bar table does not cover ;
A green progress bar indicates that ;
Cov Is the overall coverage ;
Missed Instructions Indicates code coverage ;
Missed Branches Indicates the logical branch coverage ;
Missed Cxty Indicates the number of judgments executed ;
Missed Lines Represents the number of lines of code ;
Methods Indicates the number of methods .
How to use unit test reports
thus , We talked about the importance of unit tests and how to set up and view unit test reports . Now let's talk about how to use unit test reports .
In this article, we describe two unit test reports , One is to facilitate testers to count the number of unit test cases and analyze the results of case execution from the perspective of testers surefire-report The report , The other is to help testers and developers analyze the code coverage of unit test cases jacoco The report .
about surefire-report For reporting purposes , We are mainly used to count the number of use cases and judge whether the use case design is reasonable through the use case execution results 、 Is there a problem with the test environment , Can be similar to something closer to the code layer “ A functional test ” The report .
about jacoco Unit test coverage report , We can judge whether the test case design is missing by unit test coverage , So as to complete the missing test cases . The following figure shows a Package Unit test coverage report of a method in a class .

As shown in the figure above , Green diamonds mean full coverage , Yellow diamonds indicate partial coverage , A red diamond means there is no cover .
From the above test report, we can see the lack of unit test cases covering the red part , So it can be redesigned 、 Complete the test cases corresponding to the red branch .
Summary
For most testers , There are few opportunities to contact unit testing at work . however , From the perspective of career development path and personal ability improvement , Learning unit testing can not only improve the business ability of testers , Understanding of the code , It can also improve some “ viability ” Well , It is said that “ Many hands make light work ” It is so .
Learning resource sharing
Finally, thank everyone who reads my article carefully , Watching the rise and attention of fans all the way , Reciprocity is always necessary , Although it's not very valuable , If you can use it, you can take it

These materials , For those who want to advance 【 automated testing 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful …….

边栏推荐
- 假期安全不放假,VR交通让孩子安全出行|广州华锐视点
- 说实话ThreadLocal真不是啥高级的东西
- Kalman滤波器--从高斯融合推导
- 企业中通过组策略管理Edge浏览器设置(IE模式、主页绑定等)
- Entropy - conditional entropy - joint entropy - mutual information - cross entropy
- 商业智能BI与业务管理决策思维之四:业务成本分析
- Development: how to install offline MySQL in Linux system?
- 4个技巧告诉你,如何使用SMS促进业务销售?
- 达梦数据库重新初始化实例操作记录
- 事件队列、微任务与宏任务的理解和面试题
猜你喜欢

漫画 | Oracle 被新时代抛弃了吗?

France a+ France VOC label highest environmental protection level

Connect to lab server

测试人进阶技能:单元测试报告应用指南

Ditto设置全局仅粘贴文本快捷键

Force deduction ----- count the string containing the given prefix

Kalman filter -- Derivation from Gaussian fusion

Year after year, why is breaking the data island still the primary task of enterprise development

Entropy - conditional entropy - joint entropy - mutual information - cross entropy

Kalman滤波器--从高斯融合推导
随机推荐
20220528 [talk about fake chips] those who are greedy for cheap often suffer heavy losses. Take stock of those fake memory cards and solid state drives
为什么越来越多的人选择云渲染?
Promise from recognition to use
永远不要使用Redis过期监听实现定时任务!
Abaqus 2022软件安装包和安装教程
【DesignMode】单例模式(singleton pattern)
WordPress 博客使用火山引擎 veImageX 进行静态资源 CDN 加速(免费)
Tupu software has passed CMMI5 certification| High authority and high-level certification in the international software field
Development: how to install offline MySQL in Linux system?
软件工程最佳实践——项目需求分析
测试必备工具 —— Postman实战教程
How JS correctly clears all child elements under an element
Sqlserver SQL Server Management Studio and transact SQL create accounts and create read-only users to access the specified database
事件队列、微任务与宏任务的理解和面试题
Influence and requirements of different manufacturing processes on the pad on PCB
ArcGIS无插件加载(无偏移)天地图
Task01: getting to know database and SQL (Note 1)
SQL continuous login problem
sql是否走索引
【UML】UML类图