Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of Spock's @Unroll annotation

Tags:

spock

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?

like image 429
Rostislav V Avatar asked May 21 '18 07:05

Rostislav V


2 Answers

@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.

like image 123
Royg Avatar answered Oct 17 '22 06:10

Royg


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
like image 36
Rostislav V Avatar answered Oct 17 '22 06:10

Rostislav V