p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 (http://p2p.wrox.com/forumdisplay.php?f=325)
-   -   Where are all the unit tests? (http://p2p.wrox.com/showthread.php?t=59292)

Extrakun June 20th, 2007 11:58 PM

Where are all the unit tests?
 
Hi,

One of the reasons I bought the book is because of Benjamin's emphasis on unit tests...but in the first four chapters of the code, I cannot find the unit test class.

For example, in chapter 4, TestGame is the class responsible for the unit tests. Alas, nowhere in the book is the code for TestGame shown, and TestGame cannot be found inside the downloaded code.

Did I miss something?


cannontrodder July 17th, 2007 05:39 PM

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.



All times are GMT -4. The time now is 11:35 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.