definition:
To run the tested program, it is necessary to cover all possible paths in the program.
Relationship with other coverage:
The program can be thoroughly tested, covering a wider range than statement coverage, condition coverage, decision coverage, condition judgment coverage, and condition combination coverage.
Path coverage:
Path coverage = number of paths executed at least once / total number of paths
eg: There are 4 paths in the code case, and 3 paths are executed in the design test case, then the path coverage is 3/4 = 75%
Test case:
Take the following picture as an example:
According to the above picture: if we want the coverage rate to be 100%, the
judgment conditions are as follows:
- if (x> 0 && y> 0) judgment: recorded as P1
- if (magic <0) judge: record as P2
- x> 0: recorded as C1
- y> 0: recorded as C2
- magic <0: Recorded as C3
test case design:
It can be seen from the above: the four path paths of abdf, acdf, abef, acef are executed, and the path coverage rate is 100%.
Advantages and disadvantages:
Advantages: The path coverage is very wide.
Disadvantages: Because path coverage needs to test all possible paths (including loops, conditional combinations, branch selection, etc.), then a large number of complex test cases need to be designed, resulting in an exponential increase in workload. In some cases, some execution paths cannot be executed.
Reference: https://www.bilibili.com/video/BV1wE411379A?from=search&seid=13283429216155494082