2013-07-31 74 views
1

有没有什么方法可以获得当前测试用例的类执行。通过@Rule注解,我们可以获得当前测试方法的方法名称,但是为了获得类,我无法找到我可以获得类的方式。获取当前测试用例在Junit中运行的类

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

}

我想要得到MYCLASS这样我可以实现上面的代码概括为任何含类试验方法。

在此先感谢。

回答

0

要获得类名使用

@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 
} 
相关问题