summaryrefslogtreecommitdiffstats
path: root/junit4/src/main/java/org/junit/rules/TestName.java
blob: c4ab9ced09269378ad21203b6028886364a82cea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package org.junit.rules;

import org.junit.runner.Description;

/**
 * The TestName Rule makes the current test name available inside test methods:
 * 
 * <pre>
 * public class TestNameTest {
 * 	&#064;Rule
 * 	public TestName name= new TestName();
 * 
 * 	&#064;Test
 * 	public void testA() {
 * 		assertEquals(&quot;testA&quot;, name.getMethodName());
 * 	}
 * 
 * 	&#064;Test
 * 	public void testB() {
 * 		assertEquals(&quot;testB&quot;, name.getMethodName());
 * 	}
 * }
 * </pre>
 */
public class TestName extends TestWatcher {
	private String fName;

	@Override
	protected void starting(Description d) {
		fName= d.getMethodName();
	}

	/**
	 * @return the name of the currently-running test method
	 */
	public String getMethodName() {
		return fName;
	}
}