Preparation
- Install Eclipse (classic edition) 3.3.1.1 from here
- Ensure you have JDK version 6 installed. JDK 5 may work, JDK 4 or less will definitely not work.
- Download this file and unzip it on your machine
- Launch Eclipse, create a new workspace, ensure the JRE in use is JRE version 6, ensure compiler compliance is 6.0
- 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)
- Import the 5 projects found in the InitialContent directory
- 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
-
Write a test to ensure that a deal results in the player getting two cards
- Write a test to ensure that an attempt to deal a subsequent time results in a thrown exception
- 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:
- Think, then jot down on some paper the tests you are going to write
- Design the test, keep adding to it and removing from it until you are satisified the test is correct
- Do just enough for the test to compile
- Run the test to make sure it fails
- Do just enough for the test to pass
- Run all the tests to make sure every test passes
- Re-factor, run the tests every time you make a change and check they are still all passing