Whitebox testing is a thorough type of testing usually conducted by computer programmers.
A program or algorithm is traced from beginning to end, and changes in input, variables and output are noted.
This type of testing allows programmers to determine exactly where logic and other errors may be occuring in the program.
An accountancy firm requires software that will allow a user to input tax data and output the total tax entered, the average tax, the number of tax data items entered. The program will terminate when the user enters -1.
An Algorithm engineer has produced the following pseudocode to solve the problem:
total ← 0
count ← 0
OUTPUT "Enter a tax amount: "
INPUT taxAmount
WHILE taxAmount <> -1 DO
total ← total + taxAmount
count = count + 1
OUTPUT "Enter a tax amount: "
INPUT taxAmount
END WHILE
average = total/count
OUTPUT "Total tax is ", total
OUTPUT "Average tax is ", average
OUTPUT "Number of tax items entered", count
To test this sequence of steps, the Test Engineers have identified the following test data to be input into the algorithm:
| 10 | 5 | 7 | 15 | 13 | 20 | -1 |
|---|
According to this data, they have already calculated the expected results:
| Total | Count | Average |
|---|---|---|
| 70 | 6 | 11.67 |
In order to see how the algorithm manages the test data, a trace table can be used.
A trace table lists all of the variables used in the algorithm, and traces their values as each step in the algorithm is processed.
Here is an example of a trace table for the algorithm design above:
| total | count | taxAmount | average | "Total tax is " | "Average tax is " | "Number of items " |
|---|---|---|---|---|---|---|
| 0 | 0 | 10 | ||||
| 10 | 1 | 5 | ||||
| 15 | 2 | 7 | ||||
| 22 | 3 | 15 | ||||
| 37 | 4 | 13 | ||||
| 50 | 5 | 20 | ||||
| 70 | 6 | -1 | ||||
| 11.67 | 70 | 11.67 | 6 |
Let's take a closer look at what's going on.
| 10 | 5 | 7 | 15 | 13 | 20 | -1 |
|---|
total ← 0
count ← 0
OUTPUT "Enter a tax amount: "
INPUT taxAmount
WHILE taxAmount <> -1 DO
total ← total + taxAmount
count ← count + 1
OUTPUT "Enter a tax amount: "
INPUT taxAmount
END WHILE
average = total/count
OUTPUT "Total tax is ", total
OUTPUT "Average tax is ", average
OUTPUT "Number of tax items entered", count
| total | count | taxAmount | avg | "Total" | "Average" | "Num items " |
|---|---|---|---|---|---|---|
| 0 | 0 | 10 | ||||
| 10 | 1 | 5 | ||||
| 15 | 2 | 7 | ||||
| 22 | 3 | 15 | ||||
| 37 | 4 | 13 | ||||
| 50 | 5 | 20 | ||||
| 70 | 6 | -1 | ||||
| 11.67 | 70 | 11.67 | 6 |