Structural Testing in Software Testing

What is Structural Testing in Software Testing?

Structure-based techniques serve two purposes: test coverage measurement and structural test case design.

  • They are often used first to assess the amount of testing performed by tests derived from specification-based techniques, i.e. to assess coverage.
  • They are then used to design additional tests with the aim of increasing the test coverage.
  • Structure-based test design techniques are a good way of generating additional test cases that are different from existing tests.
  • They can help ensure more breadth of testing, in the sense that test cases that achieve 100% coverage in any measure will be exercising all parts of the software from the point of view of the items being covered.

Tools Required

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

  • JBehave
  • Cucumber
  • Junit
  • Cfix

What are the techniques used to carry out Structural Testing?

Statement Coverage

In structural testing, executable code statements play a vital role when it comes to deciding the methods of designing the tests.

We aim at achieving 100% coverage, which means that every executable statement has been tested at least once. The higher the coverage, the less there is the likelihood of missing the bugs and errors.

It is required to use test cases here. The data we go for needs is to ensure that every executable statement in a block of code gets executed at least once.

Branch Coverage

This coverage level involves testing the points in the CFG branches (where decisions are made). The outcomes are boolean. Even if a switch statement is used and there are multiple outcomes, in essence, each case block is a comparison of a pair of values.

Just like with statement coverage, we should aim at 100% branch coverage. To achieve this, we need to test each outcome at each decision level at least once. Since we are dealing with boolean outcomes, then we should aim at running at least 2 tests per section of code.

Path Coverage

This level of coverage is more thorough when compared to decision and statement coverage. The aim here is to ‘discover’ all possible paths and test them at least once. This can be extremely time-consuming. It can, however, help discover bugs or errors in our code, or even aspects that we need to define, for example, user input.

Condition Coverage

Individual conditions can be put to test with Boolean inputs. The process offers better coverage and problems that were discussed under branch coverage can be rectified in this process.

What are the different types of Structural Testing in Software Testing?

There are further many types of structural testing that can take place. The structural testing is based on different types of approaches. The approaches vary for each and are listed below:

  • Control flow testing: The basic model of the testing is the flow of control. The whole test is based on how the control is carried out throughout the program. This method requires detailed knowledge of all aspects of the software and the logic of the software. It tests out the whole code thoroughly.
  • Data flow testing: This implements the use of a control flow graph and checks the points where the codes can lead to an alteration in the data. In this way, the data is kept safe and unaltered throughout the execution of the program. Any alteration of the data can result in adverse consequences.
  • Slice based testing: It was originally created and developed for maintaining the software. The basic idea is to divide the whole program into small slices and then checking on to each slice carefully. This method is very useful for the maintenance of the software as well as debugging the software too.
  • Mutation testing: This is the type of software testing that requires the development of new tests to be carried out on the software for its testing. The developers make small alterations to the already available software tests and create a mutant of the old software test. This is how the name mutation testing arises. The developer then carries out the mutation tests on the program as he wishes to.

Advantages of Structural Testing

  • Provides a more thorough testing of the software.
  • Helps finding out defects at an early stage.
  • Helps in eliminating dead code.
  • Not time consuming as it is mostly automated.

Disadvantages of Structural Testing

  • Requires knowledge of the code.
  • Requires training in the tool used for testing
  • It is expensive.