This document discusses unit testing in Groovy. It begins with reviewing basics of unit test structure and organization, including parts of a test like annotations and assertions, and different styles of organizing tests by class, feature, or fixture. The document then provides an example of a Groovy unit test for a game board, showing how to test for exceptions from invalid moves and assert that valid moves are properly marked on the board. It concludes with references for further reading on testing patterns and practices.
4. Review Basics :: Parts @Test void givenValidMove_shouldMarkLocation() { int x = 1, y = 3 gameBoard.move(x, y) assertEquals "Should have been marked 'X' after the move.", X, gameBoard.getCells()[y-1][x-1] }
5. Review Basics :: Parts @Test void givenValidMove_shouldMarkLocation() { int x = 1, y = 3 assertThat "[GUARD] Makes sure that it is not 'X' ' + 'before the move.", gameBoard.getCells()[y-1][x-1], not(equalTo(X)) gameBoard.move(x, y) assertEquals "Should have been marked 'X' after the move.", X, gameBoard.getCells()[y-1][x-1] }
6. Review Basics :: Organization A. Test by Class B. Test by Feature C. Test by Fixture