O'Reilly logo

Test-Driven Java Development - Second Edition by Viktor Farcic, Alex Garcia

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Requirement 4 – the game's output

Next, we should let the player know the status of the game.

We want feedback when either an event or an error occurs within the game. The output shows the status of the board on every move.

As we are throwing exceptions when an error occurs, this is already covered, so we only need to implement these two tests. Furthermore, for the sake of testability, we need to introduce a parameter within the constructor. By introducing this parameter, the output becomes easier to test:

private OutputStream output; @Before public void beforeEachTest() { output = new ByteArrayOutputStream(); tested = new Connect4TDD(new PrintStream(output)); } @Test public void whenAskedForCurrentPlayerTheOutputNotice() { tested.getCurrentPlayer(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required