Game Development Reference
In-Depth Information
class Player
{
public int Health { get; set; }
}
Now all the tests can be run using the unit-testing software. The test will fail
because by default, integers are initialized to zero. To pass the test, the code must
be altered.
class Player
{
public int Health { get; set; }
Player()
{
Health ¼ 10;
}
}
Running the unit-testing software again, the test will pass. We now know this
code is working under the tested condition. Let's add two more tests.
class PlayerTests
{
bool TestPlayerIsHurtWhenHit()
{
Player p ¼ new Player();
int oldHealth ¼ p.Health;
p.OnHit();
if (p.Health < oldHealth)
{
return true;
}
return false;
}
bool TestPlayerIsDeadWhenHasNoHealth()
{
Player p ¼ new Player();
p.Health ¼ 0;
if ( p.IsDead() )
{
return true;
}
Search WWH ::




Custom Search