Search code examples
spock

Spock's @Unroll vs. @Stepwise


Say I have a Specification with a single @Unroll test in it

class MySpec extends Specification {

  @Unroll
  def "some test, executed n times, with n>1"() {
    // when, then, where
  }
}

Would it be redundant to annotate MySpec to be executed @Stepwise? Is this treated as one test (executed n times in a row) or as n tests (executed in parallel)?


Solution

  • @Stepwise ensures that all test methods run in the order shown in the source file.

    @Unroll is useful for parameterized tests because it forces all test scenarios in a single test method to be reported as individual test runs.

    So in your case @Stepwise is redundant and all unrolled tests are executed in the order as specified in the where clause.

    Generally in Spock 1.x all tests are executed in row and even those unrolled from where clause. Parallelism is planned for Spock 2.0 - as you can see here https://github.com/spockframework/spock/issues/157