2014-05-02 18 views

回答

3

使用JUnit的@Rule TestName。這適用於舊式JUnit測試和spock規範。

實施例:

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" 
     .... 
    } 
}