恐らく、メソッドを削除する命令は無いのではないかと思います。
やりたい事としてはテストメソッド名を取得しながら、テストをする、という事ですよね。
であれば、下記が参考になるのではないでしょうか。参考
拡張したRunner
java
1package sample;
2
3import java.lang.reflect.Method;
4
5import org.junit.internal.runners.InitializationError;
6import org.junit.internal.runners.JUnit4ClassRunner;
7import org.junit.runner.notification.RunNotifier;
8
9public class ContextRunner extends JUnit4ClassRunner {
10
11 public ContextRunner(Class<?> klass) throws InitializationError {
12 super(klass);
13 }
14
15 @Override
16 protected void invokeTestMethod(Method method, RunNotifier notifier) {
17 TestContext.start(method);
18 super.invokeTestMethod(method, notifier);
19 TestContext.end();
20 }
21}
テストメソッドを保持するクラス
java
1package sample;
2
3import java.lang.reflect.Method;
4
5public class TestContext {
6
7 private static final ThreadLocal<TestContext> threadLocal =
8 new ThreadLocal<TestContext>();
9
10 public static void start(Method m) {
11 threadLocal.set(new TestContext(m));
12 }
13
14 public static void end() {
15 threadLocal.remove();
16 }
17
18 public static TestContext getContext() {
19 return threadLocal.get();
20 }
21
22 private Method testMethod;
23
24 private TestContext(Method testMethod) {
25 this.testMethod = testMethod;
26 }
27
28 public String getName() {
29 return testMethod.getName();
30 }
31}
テスト
java
1package sample;
2
3import static junit.framework.Assert.*;
4
5import org.junit.Test;
6import org.junit.runner.RunWith;
7
8@RunWith(ContextRunner.class)
9public class SampleTest {
10
11 @Test
12 public void hoge() {
13 TestContext ctx = TestContext.getContext();
14 assertNotNull(ctx);
15 assertEquals("hoge", ctx.getName());
16 }
17}