Last active
August 29, 2015 14:27
-
-
Save TheSecretSquad/01a2f6ea9c708489e7da to your computer and use it in GitHub Desktop.
This file contains 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
// 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