[英]How to write JUNIT test case for a class which implements ApplicationListener<ApplicationPreparedEvent>
[英]Get Class in which current test case is running in Junit
有沒有辦法讓當前測試用例的類執行。 通過@Rule批注,我們可以獲得當前測試方法的方法名稱,但是要獲取類,我無法找到獲取類的方法。
public void setUp() throws Exception
{
Method method=MyClass.class.getMethod(testName.getMethodName());
}
我想要獲得Myclass,以便可以對包含測試方法的任何類在上述代碼中實現概括。
提前致謝。
要獲取類名,請使用
@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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.