org.junit.rules
Class TestName

java.lang.Object
  extended by org.junit.rules.TestWatcher
      extended by org.junit.rules.TestName
All Implemented Interfaces:
TestRule

public class TestName
extends TestWatcher

The TestName Rule makes the current test name available inside test methods:

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

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

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

Since:
4.7

Constructor Summary
TestName()
           
 
Method Summary
 String getMethodName()
           
protected  void starting(Description d)
          Invoked when a test is about to start
 
Methods inherited from class org.junit.rules.TestWatcher
apply, failed, finished, skipped, succeeded
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestName

public TestName()
Method Detail

starting

protected void starting(Description d)
Description copied from class: TestWatcher
Invoked when a test is about to start

Overrides:
starting in class TestWatcher

getMethodName

public String getMethodName()
Returns:
the name of the currently-running test method