Skip to content

Instantly share code, notes, and snippets.

@charlieamat
Last active March 6, 2017 20:56
Show Gist options
  • Save charlieamat/4db3ce79390e7be3051d6f0e81adad9b to your computer and use it in GitHub Desktop.
Save charlieamat/4db3ce79390e7be3051d6f0e81adad9b to your computer and use it in GitHub Desktop.
Why is Unit Testing So Hard? - Example 1
public class StrongWeapon : Weapon
{
public override double Damage => 5.0;
}
public class Player
{
private Weapon _weapon;
public double Damage => _weapon.Damage;
}
public class PlayerView
{
private Player _player;
public string WeaponLabelText => $"Weapon Damage: {_player.Damage}";
}
public class PlayerTests
{
[Test]
public void StrongWeaponDamage()
{
var weapon = new StrongWeapon();
Assert.AreEqual(5.0, new Player(weapon).Damage);
}
}
public class PlayerViewTests
{
[Test]
public void StrongWeaponLabelText()
{
var weapon = new StrongWeapon();
var player = new Player(weapon);
Assert.AreEqual("Weapon Damage: 5", new PlayerView(player).WeaponLabelText);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment