Introduction to Structural Testing
Structural Testing is a type of testing in which the complete code of the application is tested. This is different from the other type testing which black box where the main concentration is on the type of output generated rather than the way the output generated.
when the software is developed it is expected to be tested from all the aspects so that the production environment is defects free. There are different testing strategies and structural testing is one of them. In software testing basically the outputs are generally matched with the expected output.
There are two main methodologies of two testing’s and they are often referred to as white-box testing and black-box testing. Structural testing is generally a white box testing where the main consideration is on the structure of the code. In the black box testing, the output result is compared with expected result but how the output or what is the code that generated the output is not tested. This testing is taken care of by the structural testing.
Structural Testing with Diagram
Since here the code is being tested it is expected that the associate who is testing has a good understanding of the programing language in which the code has been written. The structural testing is concentrated on how the system is doing rather than the functionality of the system. Thus this testing is just the opposite of behavioral testing. Most of the time structural testing is also referred to as white Box Testing and also as open, transparent or glass testing basing on the code.
We can see the above diagram. With white box testing, we are passing the input and we are monitoring that who the input is traversing and being acted upon to generate the output. This is not the case with the black box testing as it is the mainly considering that the output is as per expectation of the functional requirement. In a way, all the standards of the code and associated risks get captured in the structural testing only.
Now let us see a few of the techniques of structural testing. Below are a few structural techniques.
- Statement Coverage
- Path Coverage
- Branch Coverage
1. Statement Coverage
The main aim of this technique of structural testing is to make sure all the statements of the code gets tested. The adequacy criterion should be 1 which makes sure that we have 100% coverage. This good in testing each statement or part but this technique not good in testing the control flow. This can be illustrated from below diagram
In the above diagram N1, N2, N3, N4, N5 will be basic blocks to be tested and E1 to E5 represents the edges. This N1-N5 is sequences of the statements and E1- E5 are edges that indicates the control flow. Now in statement coverage, the nodes will be covered by below two steps
E1 -> E2 -> E5 E1 -> E3
you can see that the E4 is missed which is control flow. N3 is having two exits E5 and E4 but since N4 block or statement is already covered by E3, E4 will not be covered and hence one E5 will be taken from N3. This is one flaw in statement coverage.
2. Path Coverage
These techniques supposedly used to tests different paths from entry to exit points without a miss and this can be different combinations of decisions taken in the sequence. Some time path can be too many to be tested such as in case of larger loops. This can be avoided by adopting cyclomatic complexity that helps in identifying the redundant test cases and eliminate them. Thus we can test linearly the independent paths using cyclomatic complexity in path coverage.
3. Branch Coverage
Branch coverage aims to test all the edges or branches of the code. Thus the E4 that was getting missed as part of statement coverage will be covered here. Thus branch covaerhe provide better solution to coverage testing by solving the shortcoming of statement covergae. Let us look at below diagram to get better understanding of branch coverage.
here full 100% branch coverage is provided by following E1 -> E2
but we can see that E1 is a TRUE branch and we can obtain TRUE conditions by multiple conditions. But branch test main aim to test each branch once. This E1 which an evaluate True on multiple conditions such as (A>2 [True] and B>8 [False]. This evaluates E1 as True) or (A<2 [False] and B<8 [True] which again evaluates E1 as True). This short come is tested in conditional coverage.
4. Conditional Coverage
The main aim of this techniques are to test all the possible combinations of conditions along with that of the one, we missed in branch coverage. Thus even though this looks like an extension of branch coverage, it provides better coverage. But there is one problem associated with conditional coverage and that is getting exponentially increased conditions due to numerous combinations that need to be avoided.
Advantages and Disadvantages of Structural Testing
Below are the advantages and disadvantages:
Below are the advantages:
- It provides thorough testing of the code and finally the software
- All the early defects can easily be identified
- It eliminates the dead code or statements
- The steps of structural can be automated if you have time
- Translational errors while typing, unwanted Risks with the data and other technical standards can easily be validated with this testing
Below are the disadvantages:
- There are few shortcomings in each technique as discussed in each coverage even though there are alternates
- Heavy dependency on the skill set of the tester as thee code component is tested
- Since this is more detailed testing, it is quite
Thus in this article we have seen the structural testing in detail like what are the different techniques and how are they different from each other. We also got answers for how structural testing is different from behavioral testing etc. This if the project is hugely critical and the user does not want to take any chance then they opt for structural testing as it more robust testing.
This is a guide to Structural Testing. Here we discuss an introduction to Structural Testing along with techniques and block diagrams. You can also go through our other related articles to learn more –