How to get name of currently running test in spock?

后端 未结 2 830
[愿得一人]
[愿得一人] 2021-01-17 10:02

In JUnit 3, I could get the name of the currently running test like this:

public class MyTest extends TestCase {
    public void testSomething() {
        as         


        
2条回答
  •  隐瞒了意图╮
    2021-01-17 10:12

    One solution is to leverage JUnit's TestName rule:

    import org.junit.Rule
    import org.junit.rules.TestName
    
    class MySpec extends Specification {
        @Rule TestName name = new TestName()
    
        def "some test"() {
            expect: name.methodName == "some test"
        }
    }
    

    This requires JUnit 4.7 or higher.

提交回复
热议问题