user920420
user920420

Reputation: 221

how to get test name dynamically

I have suite of fitnesse test cases from junit. and I would like to log the test or page name(from setup()) for each test case. Please let me know how I can find test or page name dynamically with sample code.

Thanks

Upvotes: 0

Views: 513

Answers (1)

Stefan Birkner
Stefan Birkner

Reputation: 24520

JUnit's TestName rule is what you're looking for.

 public class TestNameTest {
    @Rule
    public TestName name= new TestName();

    @Test
    public void testA() {
            assertEquals("testA", name.getMethodName());
    }
 }

Upvotes: 2

Related Questions