What is test scaffolding?


Scaffolding is all the components needed to create a complete unit test for a module (in Java, a class).

Read Test Plan and Testing units in isolation and JUnit and Fakes FAQ.

Here's the rules of thumb for creating scaffolding.

Position in class hierarchy
Scaffolding needed
For the lowest level units with no dependencies, a JUnit test class that exercises all the methods in the class.
For intermediate level units with dependencies A JUnit class and fake for each dependency
Console user interface
1. Fakes for each dependency.
2. A Driver:
  •  JUnit class that provides a Readable object (for example)
OR
  • Ant script that redirects input from a file.
3. (Manual) A written description of expected results, for manual verification by a human tester.
(Automated) A text file containing expected results ("the oracle") and an Ant script that runs "diff" or other comparison tool.
Graphical User Interface
1. Fakes for each dependency.
2. (Manual) A written description of how the human tester exercises the GUI  and the expected results. 
(Automated) A test script written for UISpec4J, Costello or similar GUI test tool.


Consider this dependency chart for the card game Hobknob. (View rules)
dependency chart

Exercise

In Game,
method draw()
calls Deck.dealCard()
calls CardPoints.getValue(Card card)

method undo()
calls Deck.restock() (which restores the card to the bottom of the deck.)
calls CardPoints.getValue(Card card)

Write the fakes needed for a unit test of Game.  Write the JUnit test for draw(), undo(), and gameover(). Assume Card and Counter are unit tested and available.

Write a FakeGame used for unit testing Console,
assuming console calls draw(), undo(), gameOver(), getLastDraw(), getScore(), and getTotal()


Solution