Tuesday, March 13, 2012

Spock tests modularization

It is not very clear from Spock documentation how to split Spock feature methods into multiple functions. But, for example, Geb test scenarios sometimes can be quite complicated (if you want to verify something across multiple pages) and worth extracting into multiple methods for clarity and reuse.
In practice, this is very simple and all you have to do is just extract method and define Java style asserts as it is in Spock documentation about helper classes. What is not in documentation, is that you can freely mix actions with validation in same method, so for example, you can do something like this:

def "do something"() {

def validateEverything() {
  assert text1 == 'some text'
  assert text2 == 'other text'

At least this works fine with Geb.

No comments:

Post a Comment