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

@Shared Resources that reports extraInfo during the test are throwing exception and info are added to header instead #245

Closed Frankie0701 closed 1 year ago

Frankie0701 commented 1 year ago

Our test framework has some resource to establish connection and send/receive messages. And this resource will report these messages as extra info during testing to generate the report with messages included. However, after upgrade to 2.3.2-groovy-3.0, all these info are printed as header, and after debug, we found the issue: if this resource has annotation @Shared, then it will behave as mentioned. Due to this resource require connection/disconnection, using it as @Shared will save some execution time, and this approach is widely adopted in existing tests within our organization. The issue is more from spock, just wondering if this could be done with workaround in spock-reports. DEBUG com.athaydes.spockframework.report.extension.InfoContainer - Unable to add info to report, will add it as header instead: XYZ. Problem: {} java.lang.IllegalStateException: Cannot request current feature in @Shared context at org.spockframework.runtime.SpecificationContext.getCurrentFeature(SpecificationContext.java:40) at com.athaydes.spockframework.report.extension.InfoContainer.add(SpockReportsSpecificationExtension.groovy:67) at com.athaydes.spockframework.report.extension.SpockReportsSpecificationExtension.reportInfo(SpockReportsSpecificationExtension.groovy:26)

Frankie0701 commented 1 year ago

Fixed this with the change on when @Shared resources register Specification. Currently this is registered with SetupSpecInterceptor, while if we change this with SetupInterceptor, then this IllegalStateException will be gone