JUnit で、@Before 付与したテストケースの前に動くメソッド内で、
これからテスト実行するテストケースメソッド名を取得する。
JUnit で、@After付与したテストケースの後に動くメソッド内で、
テスト実行したテストケースメソッド名を取得する。
という場合は、
@Rule を付けた org.junit.rules.TestName をテストクラスで、初期化生成するようにして、
TestName#getMethodName() で取得することができる。
import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName;
public class UserSendTest { @Rule public TestName testName = new TestName();
@Before public void before(){ System.out.println("これからテストするテストケース = "+ testName.getMethodName() ); }
@After public void after(){ System.out.println("テストしたテストケース = "+ testName.getMethodName() ); }