Updated April 15, 2023
Introduction to Coverage Types
In software testing, coverage is a technique that is used to determine whether the test cases designed for testing are actually covering the application code or not. How much code is exercised when we run those test cases. It helps to determine the software reliability. This technique can also be applied at the integration level and system level. At this level, white box techniques examine the structures such as menu structure, business process, web page structure. 100% coverage does not mean that test is tested 100%. Coverage only measures one dimension of a multidimensional concept. Two different test cases may achieve the exactly same coverage, but the input data of one may find an error that the input data of the other doesn’t. In this topic, we are going to learn about Coverage Types.
Types of Coverage
In this section, we are going to discuss various types of coverage.
1. Test coverage
Test coverage measures in some specific way the amount of testing performed by a set of tests. Basic coverage is measured as follows.
Coverage = (Number of coverage items exercised / Total number of coverage items) * 100%
Here coverage item is whatever we have been able to count and see whether the test has exercised or used his item.
Test coverage is measured based on the number of different structural elements in the system or component. Coverage can be measured at a component testing level, integration testing level, or acceptance testing or system testing levels. The coverage measures for specification based technique would apply at whichever test level the technique has been used.
2. Statement coverage
Statement coverage is the percentage of executable statement that a test suite has exercised. It is calculated using the following formula.
Statement coverage = (Number of statement exercised / Total number of statements) * 100%
According to study and research, it is stated that what is considered reasonably through block box testing may actually achieve only 60% to 75% of statement coverage. Ad-hoc testing is likely to be around 30%; it leaves the 70% of statement untested. Different coverage tools are used, but they may work in slightly different ways, so they give different coverage figures for the same set of tests for the same code. Although at 100% coverage, they should be the same. Let’s take an example.
READ X
READ Y
IF X > Y THEN Z = 0
ENDIF
To achieve the 100% statement coverage of the above-mentioned code, we required only one teat case, which ensures that variable X contains a greater value than the value of another variable Y. For example X = 25 and Y= 11.
3. Decision Coverage
Decision Coverage is the percentage of decision outcomes that a test suite has exercised. 100% decision coverage implies both 100% statement coverage and 100% branch coverage. It is an If statement, loop control statement, or a case statement where there are two or more possibilities of outcomes from the statement. With If statement, the outcome is either True or False; it depends on the value applied to logical statements. With a loop control statement, the outcome can is either perform the code within the loop or not; it depends on the state of the condition, i.e. true or false.
Decision coverage is calculated using the following formula
Decision Coverage = (Number of decision outcomes exercised / Total number of decision outcomes) * 100%
According to study and research, functional testing may achieve 40% to 60% of decision Coverage. Ad-hoc testing may achieve only 20% of decision Coverage and leaves 80% of the outcomes untested. Even if testing seems reasonable through a functional or specification based perspective, only two-thirds or three-quarters of the decision we can cover.
4. Branch coverage
Branch coverage is the percentage of branches that a test suite has exercised. 100% branch coverage implies both 100% statement coverage and 100% Decision Coverage. Branch coverage is closely related to decision coverage, and by 100% coverage, it five the same results. Decision Coverage measures the coverage of conditional branches, while branch coverage measures the coverage of both conditional and unconditional branches. Mostly decision coverage is used as it is the source of the branches. Some other coverage management tools may talk about branch coverage when they actually mean decision coverage or vise versa.
Another control flow coverage is used to measure linear code sequence and Jump coverage, condition coverage, condition determination coverage, and multiple condition coverage. This technique requires the coverage of all conditions that can affect or determine the decision outcomes.
Conclusion
In this article, we have discussed the four types of coverage – test coverage, statement coverage, decision coverage, and branch coverage. We have discussed each its working and coverage percentage. Mostly these coverage types are used to check the reliability and functionality of the test case, to check the outcomes. Each type has its own advantages and disadvantages; based on the project and test cases, one of them is used.
Recommended Articles
This is a guide to Coverage Types. Here we discuss the working and coverage percentage of the four types of coverage, and these types are used to check the reliability of the test case. You may also have a look at the following articles to learn more –