1

In my grails integration test, how do I get the the currently executing test name?

I want to do this for logging purposes.

More Than Five
  • 9,959
  • 21
  • 77
  • 127
  • Possibly a duplicate of http://stackoverflow.com/questions/10103495/find-out-a-methods-name-in-groovy – doelleri May 02 '14 at 16:39

1 Answers1

3

Use JUnit's @Rule TestName. This works with old style JUnit tests and spock specs.

Example:

import spock.lang.Specification
import org.junit.Rule
import org.junit.rules.TestName

class MyTestSpec extends Specification {
    @Rule TestName name = new TestName()

    void "test something"() {
        setup:
        println "running $name.methodName"
        ....
    }
}
ataylor
  • 64,891
  • 24
  • 161
  • 189