Software Testing Class

What is Structural Testing?

Structural testing is the type of testing carried out to test the structure of code. It is also known as White Box testing or Glass Box testing. This type of testing requires knowledge of the code, so, it is mostly done by the developers. It is more concerned with how system does it rather than the functionality of the system. It provides more coverage to the testing. For ex, to test certain error message in an application, we need to test the trigger condition for it, but there must be many trigger for it. It is possible to miss out one while testing the requirements drafted in SRS. But using this testing, the trigger is most likely to be covered since structural testing aims to cover all the nodes and paths in the structure of code.

It is complementary to Functional Testing. Using this technique the test cases drafted according to system requirements can be first analyzed and then more test cases can be added to increase the coverage. It can be used on different levels such as unit testing, component testing, integration testing, functional testing etc. Its helps in performing a thorough testing on software. The structural testing is mostly automated.

structural-testing

There are different criteria that are used to perform such testing. Before moving on to those, it is important to understand some terms.

Control Flow Graph: It is a graphical representation of the program depicting all the paths that may be transverse during the execution. It contains

For example following is a control flow graph:

N1, N2, N3, N4 and N5 represents Basic Blocks or Nodes and E1, E2, E3, E4 and E5 represents Edges. We can also observe that N2, N3, N4 and N5 together represent an IF loop.

Adequacy Criterion: This term refers to the coverage provided by a test suite.

Structural Testing Techniques:

Let’s see the different structural testing techniques or coverage’s now:

Statement Coverage:

It aims to test all the statements present in the program

Adequacy Criterion should be equal to 1 to ensure 100% coverage. It is a good measure of testing each part in terms of statements but it is not a good technique for testing the control flow. For ex:  one node can be reached from multiple other nodes, but since the aim is to cover just the statements, those conditions are not covered. It can be understood from the help of following example:

Here all the statements in the program can be covered using two flow

  1. E1->E2->E5
  2. E1->E3

But using these two statements the flow from N3 to N4 is not tested i.e. E4. It does not provide branch coverage. N3 has 2 exit points depending upon the decision statement in N3 i.e. True and False, but since N4 has already been covered, the testing for a decision statement is missed out.

Branch Coverage:

It is also known as Decision coverage testing. It aims to test all the branches or edges at least once in the test suite or to test each branch from a decision point at least once. It provides solution for the problem faced in Statement coverage. Branch E4 will be covered here as we saw in previous example.

Branch Testing provides a better coverage than Statement testing but it too has its shortcomings. It doesn’t provide a good coverage from different conditions that lead from node 1 to node 2 as it covers that branch only once. Let’s try to understand it better with the help of following example.

In this case, the 100% branch coverage can be provided as following

But as we can see edge E1 can be tested for multiple conditions, but under branch testing the aim is to just test the edge for one condition and not for multiple conditions associated to it. The different conditions can be:

Condition Coverage:

It aims to test individual conditions with possible different combination of Boolean input for the expression.

It is modification of Decision coverage but it provides better coverage and the problem discussed under Branch coverage can be resolved here. Notice the different combination of inputs in the following table 

S.No.

A B A or B

1

0 0

0

2

0 1

1

3 1 0

1

4 1 1

1

However when compound conditions are involved the no. of test cases may increase exponentially, which is not desired.

Modified Condition/Decision coverage: It is a modification of condition coverage. Its adequacy criterion can be defined as N+1 test cases for N variables. The test cases are derived such that that each variable independently affects the final output.So it provides coverage for different conditions without increasing the size of test case suit.

Path Coverage:

It aims to test the different path from entry to the exit of the program, which is a combination of different decisions taken in the sequence.

The paths can be too many to be considered for testing, for ex, a loop can go on and on. It can be avoided using cyclomatic complexity, which help in finding out the redundant test cases.

[Cyclomatic Complexity is quantitative measure of no. of linearly independent paths through a program and is used to indicate complexity of a program].

So, cyclomatic complexity helps aiming to test all linearly independent paths in a program at least once. These were some of the test coverage under this Testing.

Advantages of Structural Testing:

Disadvantages of Structural Testing:

Tools Required:

Some of the test tools that are used for White box or Structural Testing are as follow:

  1. JBehave
  2. Cucumber
  3. Junit
  4. Cfix

Over to you:

So, we can summarize that Structural Testing also known as Glass box testing or white box testing or clear box testing is to validate the structure of code. It requires deep knowledge of the code and is complementary to Functional Testing. It helps in providing more coverage under test suite using different coverage techniques such as Condition coverage, Decision coverage, path coverage etc. It can be used on any level of testing such as unit testing, component testing, integration testing etc.

Happy Testing and as usual, suggestions and views are welcome.

Exit mobile version