blob: bf726023bf681a15ffd7c327927da8763176284f (
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
40
41
|
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 {
* @Rule
* public TestName name= new TestName();
*
* @Test
* public void testA() {
* assertEquals("testA", name.getMethodName());
* }
*
* @Test
* public void testB() {
* assertEquals("testB", name.getMethodName());
* }
* }
* </pre>
*
* @since 4.7
*/
public class TestName extends TestWatcher {
private String name;
@Override
protected void starting(Description d) {
name = d.getMethodName();
}
/**
* @return the name of the currently-running test method
*/
public String getMethodName() {
return name;
}
}
|