当前位置:网站首页>Recommended by Alibaba P8, the test coverage tool - Jacobo is very practical

Recommended by Alibaba P8, the test coverage tool - Jacobo is very practical

2022-07-07 08:51:00 Software testing

Test coverage tools

Write test cases according to requirements documents and design documents in the test process 、 Perform the test ; For more comprehensive coverage , We may also need to understand the logic of the program under test , You need to consider the input and output of each function , Execution of logical branch code , At this time, our test execution is measured by code coverage .

Coverage is an auxiliary index to measure the test effect .

01、 significance

Analyze uncovered code , So as to deduce whether the test 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 .

02、 Tool comparison

Mainstream tools in the market Emma、Cobertura、Jacoco、Clover( commercial ). Insert picture description here
Jacoco brief introduction

Jacoco Is an open source coverage tool , The target language is java. It can be embedded in Ant 、Maven in , Also provided EclEmma Eclipse plug-in unit .Jacoco Mainly through code injection ( namely Java Agent) Way to achieve the function of coverage .

Many third-party tools provide access to Jacoco Integration of , Such as :Sonar、Jenkins、IDEA, Download address :https://www.eclemma.org/jacoco/

01、 Coverage related concepts

Jacoco Support multiple coverage statistics , Include :

Line coverage (Lines): Measure whether each line of code of the program under test is executed , Determine whether at least one instruction in the standard line is executed .

Class coverage (classes)): Measurement calculation class Class file is executed .

Branch coverage (Branches,C1coverage): Measure if and switch Branch coverage of statement , Calculate the total number of components in a method , Determine what to do and what not to do Number of branches .

Method coverage (non-abstract methods): Measure the method execution of the program under test , Execution depends on whether at least one instruction in the method is executed .

Instructions covering (Instructions,C0coverage): The counting unit is a single java Binary code instructions , Instruction coverage provides information about whether the code is being executed , Measurement is complete Independent source format .

Cyclomatic complexity (CyclomaticComplexity): stay ( linear ) In combination , Calculate the minimum number of all possible paths in a method , The missing complexity also means measuring The trial case does not cover this module completely .

02、 Pile insertion and different pile insertion modes

What is pile insertion

Program pile insertion , The first is the J.C. Huang Proposed by the professor , It is to insert some probes into the program on the basis of ensuring the original logic integrity of the tested program ( Also known as “ detector ”, In essence, it is a code segment for information collection , It can be an assignment statement or a function call to collect override information ).

Through the execution of the probe and throw out the characteristic data of program operation , Through the analysis of these data , The control flow and data flow information of the program can be obtained , Then dynamic information such as logical coverage is obtained , So as to achieve the purpose of testing .

On-The-Fly and Offine Compare

On-The-Fly The pattern is JVM adopt -javaagent Parameter assignment jar File startup agent , The agent is in ClassLoader Load one class Judge whether to modify before class file , And insert the probe into class file , The probe does not change the behavior of the original method , Just record whether it has been executed .

Offine Mode is to stake the file before testing , Generate inserted piles class or jar package , Test the inserted pile class and jar package , Generate coverage information to file , Final unified treatment , Generate a report .

Offline The mode is applicable to the following scenarios :

The runtime environment does not support java agent
Deployment environment does not allow setting JVM Parameters
Bytecode needs to be converted to other virtual machine bytecode , Such as Android Dalvik VM
Dynamic modification of bytecode and other agent Conflict
Unable to customize user load class

The house needs to be built layer by layer , Knowledge needs to be learned at one point one . We should lay a good foundation in the process of learning , More hands-on practice , Don't talk much , The last dry goods here ! I stayed up late to sort out the stages ( function 、 Interface 、 automation 、 performance 、 Test open ) Skills learning materials + Practical explanation , Very suitable for studying in private , It's much more efficient than self-study , Share with you .

Get off w/x/g/z/h: Software testing tips dao

Typing is not easy , If this article is helpful to you , Click a like, collect a hide and pay attention , Give the author an encouragement . It's also convenient for you to find it quickly next time .

原网站

版权声明
本文为[Software testing]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070611468659.html

随机推荐