Game Development Reference
In-Depth Information
Like the previous test, additional functionality has been added. The player does
not yet have an Eat method. Like the previous example, Visual Studio's refactor
tools can quickly generate the required method.
class Player
{
bool _enlarged ¼ false;
internal bool IsEnlarged()
{
return _enlarged;
}
internal void Eat(string p)
{
throw new NotImplementedException();
}
}
The new test will now fail if NUnit is run. The test can be made to pass with the
following code.
class Player
{
bool _enlarged ¼ false;
internal bool IsEnlarged()
{
return _enlarged;
}
internal void Eat(string thingToEat)
{
if (thingToEat == "mushroom")
{
_enlarged ¼ true;
}
}
}
All the tests pass, proving this code is correct and working as desired. That's
basically it for unit testing. It's not a very complicated technique, but it does give
the writer faith in the code and the ability to change it without breaking
functionality.
 
Search WWH ::




Custom Search