C/C ++ unit testing theory (11)

Source: Internet
Author: User

Chapter 1 how can we ensure the test results?

 

4.1 basic indicators for measuring test results: white box coverage

The basic indicator to measure the test result is the white box coverage rate, that is, the coverage of the Code logic unit in the statistical test. The logic units of the Code mainly include: Statements (blocks), conditions, judgments, branches, and paths. There are six common white box coverage types: statement coverage, condition coverage, branch coverage, decision condition coverage, Correction Decision condition coverage, and path coverage. Each type of coverage has its own limitations. Therefore, in practice, multiple types of coverage and combination applications are required.

 

In addition to MC/DC, the formula for calculating other coverage rates is simple:
Coverage = Number of Covered logical units/total number of logical units * 100%, for example:
Statement coverage = number of overwrite statement blocks/number of all statement blocks * 100%;
C/DC = (Number of Covered conditions + Number of Covered conditions)/(number of all judgments + number of all conditions) * 100%. The number of judgments and conditions here refer to the conditions and the calculation results, that is, the judgment value and the condition value.

 

Correction condition coverage, that is, MC/DC is the European and American aviation standard. MC/DC is mainly used to check whether the relationship between the conditions in the determination is correct. It is quite sensitive to logical operators & and |, but it does not check the coverage of the code combination from the function entry to the exit, and the defects are quite obvious. The coverage of various code combinations from the path coverage check entry to the exit. Obviously, the combination of MC/DC and path coverage is the strongest coverage indicator.

 

The general method of statistical coverage is plug-in, that is, inserting the monitoring code in the tested code to monitor the execution status. The monitoring code must not affect the functional logic of the tested code.

 

 

The tool clearly identifies the coverage. statement coverage, condition coverage, and MC/DC coverage can be identified in the code, and branch coverage and path coverage can be identified in the logic structure diagram of the Code. For example, a statement with a red background is not overwritten. T before the condition indicates that the true value of the condition is not overwritten. F Before the condition indicates that the condition's false value is not overwritten. M in front of the condition indicates that MC/DC is not covered. That is to say, this condition does not affect the determination result independently. The branches in the red background are not covered. The unoverwritten path is drawn in red.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.