Control Structure testing.

Control structure testing is a group of white-box testing methods.

1.0 Branch Testing


1.1 Condition Testing

Condition testing is a test construction method that focuses on exercising the logical conditions in a program module.

Errors in conditions can be due to:

definition: "For a compound condition C, the true and false branches of C and every simple condition in C need to be executed at least once."


Multiple-condition testing requires that all true-false combinations of simple conditions be exercised at least once.  Therefore, all statements, branches, and conditions are necessarily covered.

1.2 Data Flow Testing

Selects test paths according to the location of definitions and use of variables.  This is a somewhat sophisticated technique and is not practical for extensive use.  Its use should be targeted to modules with nested if and loop statements.

1.3 Loop Testing

Loops are fundamental to many algorithms and need thorough testing.

There are four different classes of loops:  simple, concatenated, nested, and unstructured.

Examples:

[Diagram illustrating loop structures]

Create a set of tests that force the following situations:

public class loopdemo
{
private int[] numbers = {5,-3,8,-12,4,1,-20,6,2,10};

/** Compute total of numItems positive numbers in the array
* @param numItems how many items to total, maximum of 10.
*/
public int findTotal(int numItems)
{
int total = 0;
if (numItems <= 10)
{
for (int count=0; count < numItems; count = count + 1)
{
if (numbers[count] > 0)
{
total = total + numbers[count];
}
}
}
return total;
}
}


public void testOne()
{
loopdemo app = new loopdemo();
assertEquals(0, app.findTotal(0));
assertEquals(5, app.findTotal(1));
assertEquals(5, app.findTotal(2));
assertEquals(17, app.findTotal(5));
assertEquals(26, app.findTotal(9));
assertEquals(36, app.findTotal(10));
assertEquals(0, app.findTotal(11));
}



Reference: Pressman, R. Software Engineering.  Fifth Edition.