Preparation

  1. Install Eclipse (classic edition) 3.3.1.1 from here
  2. Ensure you have JDK version 6 installed. JDK 5 may work, JDK 4 or less will definitely not work.
  3. Download this file and unzip it on your machine
  4. Launch Eclipse, create a new workspace, ensure the JRE in use is JRE version 6, ensure compiler compliance is 6.0
  5. Set the linked resource path variable PACKAGES_HOME to the packages directory found in the training distribution you have unzipped (Window/Preferences/General/Workspace/Linked Resources)
  6. Import the 5 projects found in the InitialContent directory
  7. Import the codetemplates.xml into Windows/Preferences/Java/Code Style/Code Templates

If you follow these instructions you will end up with everything compiling OK in Eclipse with no errors or warnings.

Initial exercise

  1. Write a test to ensure that a deal results in the player getting two cards
  2. Write a test to ensure that an attempt to deal a subsequent time results in a thrown exception
  3. Write a test for a method 'canDeal' that returns a boolean which indicates if it is OK to deal

For example, for the first test, here is the code:

@Test public void shouldGetTwoCardsAfterDeal() {
	Game game = new Game();
	game.deal();
	assertEquals(2, game.getHand().getCards().size());
}

The TDD cycle

All code must be written following these steps:

  1. Think, then jot down on some paper the tests you are going to write
  2. Design the test, keep adding to it and removing from it until you are satisified the test is correct
  3. Do just enough for the test to compile
  4. Run the test to make sure it fails
  5. Do just enough for the test to pass
  6. Run all the tests to make sure every test passes
  7. Re-factor, run the tests every time you make a change and check they are still all passing