Search code examples
grailsgrails-2.0spock

Spock @Unroll annotation


During a recent code review, the question came up regarding whether the @Unroll annotation belongs at the class level or the method level. The class in question requires @Unroll on most of its methods but not all of them. Does declaring @Unroll incur any performance penalties if declared at the class level and not all methods of the class require it?


Solution

  • The @Unroll annotation is intended to be used on the method level. But it can also be used on the class level as indicated in the Unroll.java JavaDoc comments:

    The {@code Unroll} annotation can also be put on a spec class. This has the same effect as putting it on every data-driven feature method that is not already annotated with {@code Unroll}. By embedding the naming pattern in the method names, each method can still have its own pattern.