Skip to content

Instantly share code, notes, and snippets.

@TheSecretSquad
Last active August 29, 2015 14:27
Show Gist options
  • Save TheSecretSquad/01a2f6ea9c708489e7da to your computer and use it in GitHub Desktop.
Save TheSecretSquad/01a2f6ea9c708489e7da to your computer and use it in GitHub Desktop.
// Does it matter?
// Testing turnRight() this way tests the behavior in terms of
// another method on the same object.
// Possible problems:
// - We need to implement the other method first.
// - We need to call another method in order to verify that turnRight behaves correctly.
@Test
public void WhenTurningRight_IfPlaced_ShouldMoveInDirectionRightOfStartWhenMoved() {
placeAtStartingPositionAndDirection(); // Assume starting direction is NORTH
realToyRobot.turnRight();
realToyRobot.move();
verify(environment).moveIn(Direction.EAST);
}
// Compared to...
// Testing turnRight this way, makes it independent from move().
// It seems more focused. It has its own behavior instead of depending on move().
// Possible problems:
// - The first example tests the business logic:
// "Turning right from direction x implies moving will move in the direction to the right of x"
// This test doesn't reflect that.
@Test
public void WhenTurningRight_IfPlaced_ShouldTurnInClockwiseDirection() {
placeAtStartingPositionAndDirection(); // Assume starting direction is NORTH
realToyRobot.turnRight();
verify(startingDirection).clockwise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment