blob: 4f15bdeb2cbc1929442f068dda6b571b1c621d2e (
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
42
43
44
45
46
47
48
49
50
|
package org.junit.tests.experimental.rules;
import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
@RunWith(Enclosed.class)
public class NameRulesTest {
public static class TestNames {
@Rule
public TestName name= new TestName();
@Test
public void testA() {
assertEquals("testA", name.getMethodName());
}
@Test
public void testB() {
assertEquals("testB", name.getMethodName());
}
}
public static class BeforeAndAfterTest {
@Rule
public TestName name= new TestName();
private final String expectedName= "x";
@Before
public void setUp() {
assertEquals(expectedName, name.getMethodName());
}
@Test
public void x() {
assertEquals(expectedName, name.getMethodName());
}
@After
public void tearDown() {
assertEquals(expectedName, name.getMethodName());
}
}
}
|