21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

270 Chapter 19 ■ Testing<br />

within a black box. Black box testing is also known as functional testing because it uses<br />

only knowledge of the function of the program (not how it works).<br />

Ideally, testing proceeds by writing down the test data and the expected outcome of<br />

the test be<strong>for</strong>e testing takes place. This is called a test specification or schedule. Then<br />

you run the program, input the data and examine the outputs <strong>for</strong> discrepancies between<br />

the predicted outcome and the actual outcome. Test data should also check whether<br />

exceptions are handled by the program in accordance with its specification.<br />

Consider a program that decides whether a person can vote, depending on their age<br />

(Figure 19.1). The minimum voting age is 18.<br />

We know that we cannot realistically test this program with all possible values, but<br />

instead we need some typical values. The approach to devising test data <strong>for</strong> black box<br />

testing is to use equivalence partitioning. This means looking at the nature of the input<br />

data to identify common features. Such a common feature is called a partition. In the<br />

voting program, we recognize that the input data falls into two partitions:<br />

1. the numbers less than 18<br />

2. the numbers greater than or equal to 18<br />

This can be diagrammed as follows:<br />

Figure 19.1 The voting checker program<br />

0 17 18 infinity<br />

There are two partitions, one including the age range 0–17 and the other partition<br />

with numbers 18 to infinity. We then take the step of asserting that every number within<br />

a partition is equivalent to any other, <strong>for</strong> the purpose of testing this program. (Hence<br />

the term equivalence partitioning.) So we argue that the number 12 is equivalent to<br />

any other in the first partition and the number 21 is equivalent to any number in the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!