What is the purpose of Spock's @Unroll annotation
Asked Answered
J

2

16

I'm having difficulties in understanding the @Unroll annotation of Spock's testing framework. In the docs, it is mentioned

Indicates that iterations of a data-driven feature should be made visible as separate features to the outside world (IDEs, reports, etc.)

Still makes not much sense to me. Could someone explain in layman's terms?

Jaquelin answered 21/5, 2018 at 7:51 Comment(2)
Possible duplicate of Spock @Unroll annotationAspinwall
Sorry for being so blunt, but please be so kind as to RTFM. Thank you very much.Beano
D
21

@Unroll is to have each data driven iterations reported independently, as indicated in Spock's website.
I want to add for some more information on using @Unroll.


If you are using @Unroll please also customize your test name, it will help you with your reports, example:

@Unroll
  def "maximum of #a and #b is #c"() { ... }

When using the @Unroll each data driven iteration will be counted as a "test" that means that your test count will increase.

Use @Unroll if you have data driven tests.

Descendible answered 25/5, 2018 at 11:11 Comment(0)
J
3

Awesome description is at the Spock's website. I should have looked at it in the first place (second place actually, after doc). The main feature is, in case of a failure, the reporting will indicate with what exactly test data it failed, leaving aside the other cases.

an alternation in reporting

the output will look something like

maximum of two numbers[0]   PASSED
maximum of two numbers[1]   FAILED

Math.max(a, b) == c
    |    |  |  |  |
    |    7  0  |  7
    42         false

maximum of two numbers[2]   PASSED
Jaquelin answered 22/5, 2018 at 7:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.