简体   繁体   中英

Spock: test name and outcome in setup() cleanup() methods

I am wondering if it is possible to make the following data available in a Spock test's lifecycle methods:

  • test name in the setup() method
  • test name and test outcome in the cleanup() method

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM