5.4. Using dedicated data generators

All the previous examples of data pipes use lists (Groovy ranges also act as lists) to hold the parameters for each test iteration. Grouping parameters in a list is the more readable option in my opinion, but Spock can also iterate on the following:

  • Strings (each iteration will fetch a character).
  • Maps (each iteration will pick a key).
  • Enumerations.
  • Arrays.
  • RegEx matchers.
  • Iterators.
  • Iterables.

This list isn’t exhaustive. Everything that Groovy can iterate on can be used as a data generator. Chapter 2 even includes a Groovy Expando as an example of an iterator. Iterables and iterators are interfaces, which means that you can implement your own classes for the greatest control of how Spock uses parameters. ...

Get Java Testing with Spock now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.