I am wondering if it is possible to make the following data available in a Spock test's lifecycle methods:
The reason I am asking is that I would like send these metadata to a data sink without the need to touch each and every test.
Thanks! Martin
Try this.specificationContext.iterationInfo.name
in setup()
. Not sure if it works. In general specificationContext
is the place where I'd be looking for such data.
Update from Opal's answer:
It is now (Spock 1.1) specificationContext.currentIteration.name
For the record, you could also use
@Rule
TestName testName = new org.junit.rules.TestName()
...
println "name: $testName.methodName"
... but there seems no point.
For the other question, getting the outcome: I couldn't find a way of getting this from Spock's SpecificationContext
.
I took a quick look at org.junit.rules.TestWatcher
... but with Spock this seemed unable to detect a failed test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With