Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does TDD mean not thinking about class design?

I am making a role playing game for fun and attempting to use TDD while developing it. Many of the TDD examples I see focus on creating the test first, then creating objects that are needed to get the test to pass.

For example:

[Test]
public void Character_WhenHealthIsBelowZero_IsDead()
{
   // create default character with 10 health
   Character character = new Character();
   character.SubtractHealth(20);
   Assert.That(character.IsAlive, Is.EqualTo(false));
}

So based on this I'll create the character class and appropriate properties/methods. This seems fine and all but should my class design really come out of continually refining my tests? Is that better than mapping out the possible objects that my game will need ahead of time? For example, I would normally think of a base Character class, then subclasses such as Wizard, Fighter, Theif.

Or is a balanced approach the way to go? One where I map out the possible classes and hierarchy I'll need but writing tests first to verify they are actually needed?

like image 952
mikedev Avatar asked Jan 27 '10 18:01

mikedev


1 Answers

Should my class design really come out of continually refining my tests?

Yes.

Does TDD mean not thinking about class design?

Absolutely not. It means thinking about class design in the course of writing your tests, and the rest of your code. Class design is at play throughout the Red-Green-Refactor TDD life cycle.

like image 115
Carl Manaster Avatar answered Oct 07 '22 21:10

Carl Manaster