The structure-based technique is called as White box testing or Glass box testing. By this technique, additional test cases can be generated which are different from existing tests. It assists two purposes test coverage measurement and structural test case design. These are used to design additional tests to increase test coverage.
Test coverage measures the amount of testing executed by a set of tests derived using specification-based techniques. Coverage is measured as:
Number of coverage items exercised
Coverage = ————————————————— x 100%
Total number of coverage items
100% coverage does not mean 100% testing done. There can be a scenario where two distinct test cases execute exactly the same coverage but, input data of one detects an error while that of another does not find an error. One drawback of code coverage measurement is that it measures coverage of what has been written, i.e. the code itself but it does not detect the software that has not been written.
Steps in Structure-Based Testing
- To verify security loops in the code
- To verify the broken paths in the code
- To verify the specified flow structure
- To verify the desired output
- To verify the condition loop to check the functionality
- To verify each section of code
Types of structure-based techniques
(i) Statement coverage
Statement coverage is known as line coverage or segment coverage. It is measured as below
Number of statements exercised
Statement coverage = ————————————————— x 100%
Total number of statements
Here test scripts are designed to execute code statements. It is done to ensure that every statement is executed at least once while testing the application. Its coverage is measured as the line of code or statements executed by test scripts.
Advantages of Statement Coverage
- It verifies each line of the code to ensure that each statement is actually performing the task that it expected to perform.
- It measures the quality of the code.
- It helps in identifying the areas that prevent the execution of the code.
Disadvantages of Statement Coverage
- Statement coverage unable to test those conditions that are false.
- It fails to validate whether the loop reaches its endpoint or the point of termination
- It does not recognize logical operators.
ii) Decision coverage
Decision coverage is also known as branch coverage or all edges coverage. It is measured as below
Number of decision outcome exercised
Decision coverage = —————————————————— x 100%
Total number of the decision outcome
A decision is an IF statement, a loop control statement such as while loop or a do-while loop, or a CASE statement, where there are two or more possible exits or outcomes from the statement is possible. In these statements two or more results are possible. Its coverage is measured as the number of possible outcomes executed by test scripts.
Advantages of Decision Coverage
- It ensures that all the branches in the code are reached.
- It verifies that no branches lead to any abnormality of the program’s operation.
- It eliminates the problems that occur with statement coverage testing.
Disadvantages of Decision Coverage
- It ignores branches within Boolean expressions
iii) Condition coverage
Condition coverage is also known as Predicate Coverage. It is measured as below
Number of conditions exercised
Condition coverage = ————————————————– x 100%
Total number of conditions
Condition coverage is for Boolean expressions. Here the testing approach is to test the application with both True and False outcome for each condition. This technique needs the coverage of all conditions which determine the decision result.
Advantages of Condition Coverage
- It can verify the true or false outcome of each condition.
- It measures the conditions independently of each other.
iv) Multiple Decision
In multiple condition testing, the different combinations of condition outcomes are tested at least once. Ideally, it makes use of a combination of techniques that are most suitable for a software application. This is an exhaustive technique whereby also very difficult to achieve 100% coverage.
Other testing types which are used
Path coverage deals with the total paths that can be covered in a test case. The path is a flow of execution that follows a sequence of instructions. It covers a function from its entry till its exit point. The test cases are built based on the logical complexity measure of procedural design. In this type of testing, every statement in the code is guaranteed to have been executed at least one time. Flow Graph, Cyclomatic Complexity, and Graph Metrics are used to arrive at the basis path.
This technique is used to ensure that all the loops in the program have been executed with a fair number of times. The purpose of this coverage technique is to make sure that the loops adhere to the conditions as prescribed and do not iterate infinitely or terminate abnormally. Loop testing aims at monitoring the beginning until the end of the loop.