Game Development Reference
In-Depth Information
public void BasicTest()
{
Assert.That(true);
}
[Test]
public void StartsLifeSmall()
{
Player player
¼
new Player();
Assert.False(player.IsEnlarged());
}
}
}
The
Assert
class is part of NUnit and is the workhorse of writing the unit tests.
The function
IsEnlarged
does not exist yet. Using the refactor tools, Visual
Studio can automatically create this function. This will result in the following
code in the
Player
class.
class Player
{
internal bool IsEnlarged()
{
throw new NotImplementedException();
}
}
Running the unit test in NUnit now will result in a failure with the following
error message
PlayerTest.TestPlayer.StartsLifeSmall:
System.NotImplementedException : The method or operation is not
implemented.
The test fails because one of the methods in the
Player
class hasn't been
implemented yet. That can be solved by adding the functionality.
class Player
{
bool _enlarged
¼
false;
internal bool IsEnlarged()
Search WWH ::
Custom Search