Software testing coverage includes branch coverage, statement coverage, and condition coverage. This is a basic test concept in white-box testing. However, I recently talked to several friends who have been conducting tests for many years, it is not clear to everyone. I will discuss this issue in depth through an example below:
Let's take a look at the test coverage.Definition:
Definition 1. Statement Overwrite: It requires that every executable statement of the program under test be tested as much as possible;
Definition 2. branch coverage: All decision branches in the program should be tested as much as possible;
Definition 3. Conditional coverage: When the criterion contains multiple conditions, the values of each condition must be verified; from these definitions, we can easily understand that statement overwrite overwrites all the statements in the program. Branch overwrite overwrites every branch in the program; conditional coverage overwrites all the conditions in the judgment condition. Here is a simple example to describe 0: 1: If (A <150) | (B <200) {2: for (I =; I <100; I ++) 3: {4: println ("A");} 5:} else {6: println ("B"); 7 :}
Branch coverage:1) set a = 120 at 0, B will execute 200, 52) set a = 400 at 0, B = will execute, 6, 7 all the branches here go, that is to say, to reach the branch coverage rate of 100%, two groups of test cases should be designed
| A |
B |
| 120 |
Arbitrary |
| 200 |
400 |
Statement overwrite:1) set a = 40 at 0, B will execute 1, 2, 3, 4, 52) set a = 200 at 0, B = 400 will execute 1, 5, 6, 7 all the statements here have come, that is to say, to reach the statement coverage rate of 100%, two groups of test cases should be designed.
In the branch overwrite, Statement 3, 4 does not go
Conditional coverage:Because the first condition is if (A <150) | (B <200), you need to design a test case.
| A |
B |
Remarks |
| 40 |
50 |
All satisfied |
| 160 |
150 |
A is not satisfied, B is satisfied |
| 40 |
250 |
A is satisfied, B is not satisfied |
| 150 |
250 |
Neither a nor B is satisfied. |
You only need to overwrite all the conditions. In this way, we can clarify these concepts.