Last active
March 6, 2017 20:56
-
-
Save charlieamat/4db3ce79390e7be3051d6f0e81adad9b to your computer and use it in GitHub Desktop.
Why is Unit Testing So Hard? - Example 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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