View Single Post
  #2 (permalink)  
Old July 17th, 2007, 05:39 PM
cannontrodder cannontrodder is offline
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is in the TestGame.cs file in the Game folder in the source code.

There is a BaseGame class which does things that need to happen in the unit test environment and in the full game. For example the code to get the screen resolution and remember it is in the Initialize() method of the BaseGame class. The TestGame class and the main game class inherit from this so do not need do this themselves.

The TestGame class does very little and makes it useful to isolate the one part of your code you are testing. The idea is, you store the code you want to test in a delegate (a type of object that can hold code), call the TestGame.Start() method and it then creates the stripped down TestGame class for you but remembers the code you passed in so that it can be ran during the Draw() method of the TestGame class.

Read through it and it will make more sense. A good one is the TestBackgroundBoxes test in the TetrisGame.cs file in Chapter 4's source. Then look at the TestGame.Start() method in TestGame.cs, look at the constructor on line 41 and finally look at the Draw method in that file. The program.cs file shows how you choose between tests.