Structure-Based or Structural Testing or Whitebox Testing Techniques
There are different types of testing techniques that are there, and each technique is helpful for a particular defect. Those different testing techniques are again categorized. There are mainly two different categories are there:
- Static Techniques
- Dynamic Techniques
Again the Dynamic Techniques is divided into three more different categories, that are:
- Specification-based Testing Which also called behavioral techniques or Black Box Testing
- Structure-based Testing Which Also Called Structural Testing techniques Or White Box Testing Technique
Static Technique Diagram
Dynamic Technique Diagram
This post, we are going to discuss the structure-based testing. The structure-based testing technique uses the software or application internal structure to derive the test cases. This structure-based technique is mainly used for two purposes, which are test coverage measurement and structural test case design. That’s why the structural bae testing also called as “Glass Box Testing Technique” or “White Box Testing Technique.”
What is White Box Testing?
Especially in white box testing, it’s one type of code-based testing because here, the testers who are responsible for testing the software is to know the internal structure of the software. In this testing, the test cases are calculated after analyzing the internal structure of the system based code, branch, path, and condition coverage.
That’s why the white box testing mainly covers the following steps:
- Verifying security loops in the code
- Verifying the broken paths in the code
- Verifying the specified flow structure
- Verifying the desired output
- Verifying the condition loop to check the functionality
- Verifying each line and section
Structure-based testing can be applied for different levels of testing like:
Due to the structure-based testing technique, we can able to get to know how much code coverage is happening. We can also measure the percentage of code that has been covering by a test suite at the time of executing the test suite. There is a rule for calculating the code overage, and each test suite needs to be satisfied that, that is:
Coverage = (Number of coverage items exercised / Total number of Coverage items) * 100
We Can calculate the number of code coverage by using:
- Statement
- Decision (Branch)
- Path Coverage
Now let us go one by one and try to understand each one of the above things. But before that, let us take a scenario which can help us the above coverage things easily.
Example Scenario:
Read X
Read Y
IF X+Y > 100 THEN
Print “Large”
ENDIF
If X > 50 THEN
Print “X Large”
ENDIF
Better understanding the flow of code, we have created a simple flow chart that will help you to understand the Statement, Decision (Branch), and Path coverage.
From the above diagram
Nodes (|====|,<>) represent statement of code [E.g.: entry, exit, decisions]
Edges ( —– ) represent links between nodes
Statement Coverage
Statement coverage is a white box testing technique where all the statements of the source code executed at least once. To Calculate the statement coverage, we have to find out the shortest number of paths which are cover all the nodes.
It is a good measure for testing each statement, but its not a good technique for testing the control flow. For testing the code coverage Cantata++ is one of the most popular tools.
From the above flow chart in case of “Yes,” while traversing through each statement of code and the traversing path (A1-B2-C4-5-D6-E8), all the nodes are covered. So by traveling through only one way, all the nodes (A, B, C, D, and E) are covered.
Statement coverage (SC) =1
Branch/Decision Coverage
Branch coverage covers both (true and false). In this coverage, we try to cover all possible outcomes of each condition like if-else, for loop, and other conditional loops statements at least once.
This is also one type of white box testing technique that ensures that every possible branch from each decision point in the code is executed at least once. To calculate Branch coverage, find out the minimum number of paths that ensure coverage of all the edges. We can use the TCAT-path to find out the decision coverage or branch coverage.
In the above example, in case of traversing through a ‘Yes’ decision, path (A1-B2-C4-5-D6-E8), maximum numbers of edges (1, 2, 4, 5, 6, and 8) are covered, but edges 3 and 7 are left out. To cover these edges, we have to follow (A1-B3-5-D7). So by traveling through two paths (Yes, No), all the edges (1, 2, 3, 4, 5, 6, 7, 8) are covered.
Branch Coverage /Decision Coverage (BC) = 2
Path Coverage
In this coverage technique, we should execute every statement in the program guaranteed that the statements are executed at least once. This coverage techniques ensure that all the paths are covering from beginning to end. In the above flow chart, the possible paths are:
A1-B3-5-D7
A1-B2-C4-5-D6-E8
A1-B2-C4-5-D7
A1-B3-5-D6-E8
Path coverage (PC) = 4
Condition Coverage
This is much related to the decision coverage but its better sensitivity to the control flow. In condition coverage, it reports the outcomes of both true and false conditions. Lets us take an example to understand the condition coverage:
IF (“X && Y”)
To find the condition coverage, the following tests will be sufficient:
TEST 1: X=TRUE, Y=FALSE
TEST 2: X=FALSE, Y=TRUE
Final Words:
Structural testing is more concerned with how the system does rather than the functionality of the software or application. Structural Testing provides more coverage to the testing. Structural Testing helps in performing thorough testing on software.
Leave a Reply