Testing with Spock #14
Replies: 2 comments
-
Thanks @donaldsiziba for the suggestion, I merged the PR, so now the demo example shows both the usage of jUnit and Spock. I hadn't used Spock, but want to look into it more. The interesting thing about Spock is that it's like Cucumber, but inline, and as you mentioned serves the full English sentences can be served to provide easy documentation, so that this documentation can be shared with business. The other alternative is making one's own custom DSL. The disadvantage I would see is if the tests are read-only by developers, then the full English sentences add overhead. What are the possibilities regarding documentation generation? |
Beta Was this translation helpful? Give feedback.
-
I used Spock in some projects. I love the idea. Unfortunately, the dynamic nature of Grooby makes it very hard to do refactors. We had a lot of issues which resulted in broken tests after applying only structural refactor. Therefore, in the current project we decided to use JUnit 5 with descriptive @DisplayName written in full sentecnes using multiline string blocks, e.g.: @DisplayName("Tic Tac Toe game")
class TicTacToeTest {
// @formatter:off
@DisplayName(
"""
given X player made the move at (0,0),
when O player makes the move at (1,0),
then first row is XO_
"""
)
// @formatter:on
@Test
void moveTest() {
// given
var board = new Board();
var ticTacToe = new TicTacToe(board);
ticTacToe.makeNextMove(new Coordinates(0, 0));
// when
ticTacToe.makeNextMove(new Coordinates(1, 0));
// then
var state = ticTacToe.state();
assertThat(state.boardArray()).isDeepEqualTo(new char[][]{
{'X', 'O', '_'},
{'_', '_', '_'},
{'_', '_', '_'}
});
}
} |
Beta Was this translation helpful? Give feedback.
-
After watching the TDD and Clean Architecture - Use Case Driven Development presentation by @valentinacupac, I reached out to her with a suggestion if she would consider writing her tests using Spock. Spock is an alternative test framework written in Groovy.
I usually use Spock for my tests because I love how expressive it is.
Here are some cool features of Spock:
allowing for easy documentation.
allowing for easy documentation.
library.
Here is a TDD Kata that I did years ago - I use Spock for the test cases.
Beta Was this translation helpful? Give feedback.
All reactions