groovyspock

Dynamically append value to spock test method name based on method annotation


We have a large Spock test suite, across mulitple teams, each teams tests have an annotation on them such as @Team5.

I would like to append - @Team5 dynamically to the end of each test methods name that is marked with that annotation so that for reporting test failures it easy to see which team is responsible for each failure.

I've looked into writing a spock extension but I cannot seem to find any spots where I could actually alter the feature name, am I just missing something?


Solution

  • You can modify the displayName of INameable implemented by SpecInfo, FeatureInfo, and IterationInfo via an extension. See Spock's built-in TitleExtension as an example. See also the UnrollExtension if you want to modify iteration names.