Skip to content

Instantly share code, notes, and snippets.

@ecmendenhall
Last active December 17, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecmendenhall/5523091 to your computer and use it in GitHub Desktop.
Save ecmendenhall/5523091 to your computer and use it in GitHub Desktop.
Testing printed terminal output with JUnit 4.
@RunWith(JUnit4.class)
public class TerminalViewTest extends TicTacToeTest {
private final PrintStream stdout = System.out;
private final ByteArrayOutputStream output = new ByteArrayOutputStream();
private TerminalView terminalview;
@Before
public void setUp() throws UnsupportedEncodingException {
terminalview = new TerminalView();
System.setOut(new PrintStream(output, true, "UTF-8"));
}
@Test
public void terminalViewShouldPrintBoards() {
terminalview.print(nowins);
assertEquals(nowins.toString(), output.toString());
}
@After
public void cleanUp() {
System.setOut(stdout);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment