renatoathaydes / spock-reports

This project creates a global extension to Spock to create test reports.
Apache License 2.0
273 stars 68 forks source link

@Unroll annotation support #260

Closed avenue68 closed 2 months ago

avenue68 commented 2 months ago

Is it possible to have the string passed @Unroll annotation with test method name? Like in IntelliJ IDEA, the reports are shown with both test method name and unrolled examples like bellow.

class MySpecification extends Specification {

    @Unroll("My example of feature1 #iterationIndex")
    def "My feature1"() {
        ...
    }

    @Unroll("My example of feature2 #iterationIndex")
    def "My feature2"() {
        ...
    }

}
My feature1
  ✅ My example of feature1 1
  ✅ My example of feature1 2
  ✅ My example of feature1 3
My feature2
  ✅ My example of feature2 1
  ✅ My example of feature2 2
  ✅ My example of feature2 3

But the generated reports by spock-reports only include feature names like My feature1[1].

renatoathaydes commented 2 months ago

I believe you shouldn't use @Unroll anymore, as that's the default. I think you can achieve the same result by just using #var variables in the method name itself:

import spock.lang.Specification

class MySpecification extends Specification {

    def "My feature: value=#value"() {
        expect:
        value
        where:
        value << [1, 2, 3]
    }
}
Screenshot 2024-07-03 at 11 01 08
avenue68 commented 2 months ago

I know the feature method name supports unrolling by default but I wanted to represent the feature and its examples respectively. But it seems better to make method name represent feature without @Unroll and given, when, then blocks represent examples with variables. Fortunately your solution let each blocks have variables in them.

Thank you for replying!