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.

276 Chapter 19 ■ Testing<br />

3. apply the test again<br />

4. and so on until the test succeeds.<br />

However, when you fix a bug you might introduce a new bug. Worse, this new bug<br />

may not manifest itself with the current test. The only safe way to proceed is to apply<br />

all the previous tests again. This is termed regression testing. Clearly this is usually a <strong>for</strong>midable<br />

task. It can be made much easier if all the testing is carried out automatically,<br />

rather than manually. In large developments, it is common to incorporate revised components<br />

and reapply all the tests once a day.<br />

Formal verification<br />

Formal methods employ the precision and power of mathematics in attempting to verify<br />

that a program meets its specification. They place emphasis on the precision of the<br />

specification, which must first be rewritten in a <strong>for</strong>mal mathematical notation. One such<br />

specification language is called Z. Once the <strong>for</strong>mal specification <strong>for</strong> a program has been<br />

written, there are two alternative approaches:<br />

1. write the program and then verify that it con<strong>for</strong>ms to the specification. This<br />

requires considerable time and skill.<br />

2. derive the program from the specification by means of a series of trans<strong>for</strong>mations,<br />

each of which preserve the correctness of the product. This is currently the favored<br />

approach.<br />

Formal verification is very appealing because of its potential <strong>for</strong> rigorously verifying<br />

a program’s correctness beyond all possible doubt. However, it must be remembered<br />

that these methods are carried out by fallible human beings, who make mistakes. So<br />

they are not a cure-all.<br />

Formal verification is still in its infancy and is not widely used in industry and commerce,<br />

except in a few safety-critical applications. Further discussion of this approach is<br />

beyond the scope of this book.<br />

19.7 ● Unit testing<br />

When we discussed black box and white box testing above, the programs were very<br />

small. However, most software consists of a number of components, each the size of a<br />

small program. How do we test each component? One answer is to create an environment<br />

to test each component in isolation (Figure 19.2). This is termed unit testing. A<br />

driver component makes method calls on the component under test. Any methods that<br />

the component uses are simulated as stubs. These stubs are rudimentary replacements<br />

<strong>for</strong> missing methods. A stub does one of the following:<br />

■ carries out an easily written simulation of the mission of the component<br />

■ displays a message indicating that the component has been executed<br />

■ nothing.

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

Saved successfully!

Ooh no, something went wrong!