3

Is there any way to get class of current test case executing. By @Rule annotation we can get method name of current test method but to get class I am not able to find the way by which I can get class.

public void setUp() throws Exception
{
  Method method=MyClass.class.getMethod(testName.getMethodName());

}

I want to get Myclass so that I can achieve generalization in above code for any class containing test method.

Thanks in Advance.

4

1 回答 1

2

获取类名使用

@Test
public void setUp() throws Exception
    Class clazz = this.getClass(); //if you want to get Class object
    String name = clazz.getCanonicalName(); //you want to get only class name
}
于 2013-07-31T15:07:49.923 回答