0
5.1kviews
Loop - Testing
0
193views

Loop testing can be viewed as an extension to branch coverage. Loops are important in the software from the testing viewpoint. If loops are not tested properly, bugs can go undetected. This is the reason that loops are covered in this section exclusively. Loop testing can be done effectively while performing development testing (unit testing by the developer) on a module. Sufficient test cases should be designed to test every loop thoroughly.

There are four different kinds of loops. The testing of each kind of loop is discussed below.

1. Simple Loops

Simple loops mean that we have a single loop in the flow, as shown in figure 1.

The following test cases should be considered for testing simple loops.

• Check whether you can bypass the loop or not. If the test case for bypassing the loop is executed and still you enter inside the loop, it means their is a bug.
• Check whether the loop control variable is negative.
• Write one test case that executes the statements inside the loop.
• Write test cases for a typical number of iterations through the loop.
• Write test cases for checking the boundary values of the maximum and minimum number of iterations defined (say min and max) in the loop. It means we should test for $\min$, $\min +1$, $\min -1, \max -1, \max ,$ and $\max +1$ number of iterations through the loop.

2. Nested Loops

When two or more loops are embedded, it is called a nested loop, as shown in Fig.2. If we have nested loops in the program, it becomes difficult to test. If we adopt the approach of simple tests to test the nested loops, then the number of possible test cases grows geometrically. Thus, the strategy is to start with the innermost loops and hold outer loops to their minimum values. It must be continued outward in this manner until all loops have been covered.

3. Concatenated Loops

The loops in a program may be concatenated (Fig.3). Two loops are concatenated if it is possible to reach one after exiting the other, while still on a path from entry to exit. If the two loops are not on the same path, then they are not concatenated. The two loops on the same path may or may not be independent. If the loop control variable for one loop is used for another loop, then they are concatenated, but nested loops should be treated like nested only.

4. Unstructured Loops

This type of loops is really impractical to test and they must be redesigned or at least converted into simple or concatenated loops.