Subject : Guided inspection, mock objects, interaction testing, coverage.
Downloads:
Slides available here (after the lecture.)
Code from the demos available here.
Text : [MS] Chapter 5 and 6. [Expected reading time 8 hours.]
Some typos:
[MS, p. 116] line -2, "..the test coverage is 67%" (not 75% since 12/18 ~ 0.67)
[MS, p. 177] in the table on the middle of the page, third column, third row: should be "OUT.speed=100" (not 1000).
Comment : In the lecture this time we will talk about guided inspection (from Chapter 4) and move on to interaction testing described in Chapter 6. Chapter 5 describes how to semi-systematically construct test-cases from pre- and post-conditions as we talked about in the last lecture. We will talk about mock objects as a means for extending automatic unit testing towards automatic interaction testing. After this lecture we have now completed describing test methods for all phases in an iterative, incremental software development process.
Consider the FifteenPuzzle as described in the slides from the lecture (link available above). Write down a test suite of at least 5 test cases you would like to run on any implementation of FifteenPuzzle. The test suite should test for at least functionality and robustness.
Write an implementation of FifteenPuzzle. FifteenPuzzle is described in the slides from the lecture (link available above).
Hint. The following variable declarations could be used:
private final int grid[][]; // grid of numbers 0, 1, ..., 15
private int blankRow, blankColumn; // position of blank (i.e., the number 0) in grid
Implement your test cases from T.0 as methods test1(),...,test5() in your implementation of the class FifteenPuzzle. (Less ideally, if you have not yet implemented FifteenPuzzle yourself, you can use the implementation linked to in the next paragraph.) It is ok to check the outcome of the tests by manual inspection and not automatically by having code do it.
Run your tests on the implementation. Any surprises? Fix any bugs found. Rerun. How well would you say the code is now tested? Now study this implementation of FifteenPuzzle. If you implemented the class as agreed on in the specification the interface should be the same. Can you re-use your tests if you swap in the new implementation?
How would you evaluate the Testability of our FifteenPuzzle design?
Write a unit test using the JUnit framework to implement the test suite from exercise T.1. Change the FifteenPuzzle design to be more test friendly. Run your tests from within Eclipse. Change the implementation of FifteenPuzzle to make the tests fail one at a time. Run the tests and see them fail.
Extend you test suite to a test suite with at least 10 test cases covering all the major aspects of functionality and robustness. Run your tests from within Eclipse.
Set up your environment including classpath and installation of JUnit so that you can run unit tests from a command prompt. Do that on the tests from T.2 or T.3.
In the note Systematic software test, Peter Sestoft, 1998 examples of erroneous programs and tests for them are given. In this exercise we use example 1 in section 2.1, p.3.
Proceed as in T.6 but with example 2, section 3.3, p. 5 from Sestoft's note.
In this exercise we will implement and test Quicksort using JUnit. It is described in RS Chapter 7.