1import org.junit.rules.TestName;2import org.junit.Rule;3import org.junit.Test;4import static org.junit.Assert.assertEquals;5public class TestNameTest {6 public TestName name = new TestName();7 public void testA() {8 assertEquals("testA", name.getMethodName());9 }10 public void testB() {11 assertEquals("testB", name.getMethodName());12 }13}14package com.javacodegeeks.junit;15import org.junit.rules.TestName;16import org.junit.Rule;17import org.junit.Test;18import org.junit.runner.RunWith;19import org.junit.runners.Parameterized;20import org.junit.runners.Parameterized.Parameters;21import static org.junit.Assert.assertEquals;22import java.util.Arrays;23import java.util.Collection;24@RunWith(Parameterized.class)25public class TestNameTest {26 public TestName name = new TestName();27 public static Collection<Object[]> data() {28 return Arrays.asList(new Object[][] { { 1, 1 }, { 2, 2 }, { 3, 3 } });29 }30 private int mInput;31 private int mExpected;32 public TestNameTest(int input, int expected) {33 mInput = input;34 mExpected = expected;35 }36 public void test() {37 assertEquals(mExpected, mInput);38 System.out.println(name.getMethodName());39 }40}41package com.javacodegeeks.junit;42import org.junit.rules.TestName;43import org.junit.Rule;44import org.junit.Test;45import org.junit.runner.RunWith;46import org.junit.runners.Parameterized;47import org.junit.runners.Parameterized.Parameters;48import static org.junit.Assert.assertEquals;49import java.util.Arrays;50import java.util.Collection;51@RunWith(Parameterized.class)52public class TestNameTest {53 public TestName name = new TestName();54 @Parameters(name = "{index}: testAdd({0}+{1})={2}")55 public static Collection<Object[]> data() {56 return Arrays.asList(new Object[][] { { 1, 1, 2 }, { 2, 2, 4 }, { 3, 3, 6 } });57 }