Spock @Unroll 注释

Spock @Unroll annotation

在最近的一次代码审查中,出现了关于 @Unroll 注释属于 class 级别还是方法级别的问题。有问题的 class 的大部分方法都需要 @Unroll,但不是全部。如果在 class 级别声明并且并非 class 的所有方法都需要它,那么声明 @Unroll 是否会导致任何性能损失?

@Unroll 注释旨在用于方法级别。但它也可以在 class 级别上使用,如 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.