我編寫了一個自定義JUnit運行器,我希望成爲eclipse插件的一部分,該插件將使用此運行器啓動測試,而不必將@RunWith註釋應用於班上。我使用org.eclipse.debug.ui.launchShortcuts擴展點設法在'Run As'上下文菜單下獲得了一個額外的項目。但是,我不確定如何使用我的自定義亞軍來調用測試。使用自定義JUnit運行器實現從eclipse插件啓動JUnit測試
2
A
回答
3
所以我想出了一個辦法去做我想要的。但是,它看起來有點冒險。但是,我認爲我會在這裏發佈答案,以防其他人遇到同樣的問題。
首先,你必須註冊一個JUnit一種這樣的:
<extension point="org.eclipse.jdt.junit.internal_testKinds">
<kind
id="my.junit.kind"
displayName="Your Kind Name"
finderClass="org.eclipse.jdt.internal.junit.launcher.JUnit4TestFinder"
loaderPluginId="org.eclipse.jdt.junit4.runtime"
loaderClass="your.test.loader.MyLoaderClass">
<runtimeClasspathEntry pluginId="org.eclipse.jdt.junit4.runtime" />
<runtimeClasspathEntry pluginId="org.eclipse.jdt.junit.core" />
<runtimeClasspathEntry pluginId="org.eclipse.jdt.junit.runtime"/>
</kind>
</extension>
在XML必須指定的org.eclipse.jdt.internal.junit.runner.ITestLoader
自定義實現這反過來又返回org.eclipse.jdt.internal.junit.runner.ITestReference
的實現。核心部分是ITestReference的實現,因爲這是您創建自定義JUnit運行器實例的地方。
public class MyTestReference extends JUnit4TestReference
{
public MyTestReference(final Class<?> p_clazz, String[] p_failureNames)
{
super(new Request()
{
@Override
public Runner getRunner()
{
return new MyCustomRunner(p_clazz);
}
}, p_failureNames);
}
...
}
然後最後你有一個啓動快捷鍵設置的那種適當
public class MyJunitLaunchShortcut extends JUnitLaunchShortcut
{
@Override
protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(IJavaElement p_element) throws CoreException
{
ILaunchConfigurationWorkingCopy config = super.createLaunchConfiguration(p_element);
config.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_RUNNER_KIND, "my.junit.kind");
return config;
}
}
這確實使用了一堆內部類的鏈接這一點,所以有可能是一個更好的辦法。但是,這似乎工作。
相關問題
- 1. JUnit測試自定義Eclipse構建器
- 2. 運行JUnit插件測試時防止啓動eclipse GUI
- 3. 寫eclipse junit插件測試
- 4. Eclipse如何實際運行Junit測試?
- 5. 如何使用JMock運行JUnit Eclipse插件測試?
- 6. 如何使用eclipse中的Ant運行Junit插件測試
- 7. 運行JUnit測試套件在Eclipse
- 8. 從junit測試啓動jmeter
- 9. 從Eclipse插件運行JUnit測試並訪問結果
- 10. Buckminster:運行JUnit插件測試headless
- 11. java.lang.NoClassDefFoundError運行JUnit插件時,測試
- 12. JUnit無法啓動JUnit插件測試。爲什麼?
- 13. Junit測試用例生成器(JUB)插件Eclipse for Junit測試用例自動化
- 14. 使用JUnit進行自動化測試
- 15. 使用Maven運行JUnit測試套件
- 16. 在Eclipse的JUnit運行使用JUnit @rule
- 17. 如何爲SureFire Maven插件指定JUnit自定義運行器?
- 18. ClassNotFoundException:在Eclipse中運行JUnit測試
- 19. 無法在Eclipse中運行junit測試
- 20. Eclipse grails作爲JUnit測試運行
- 21. 從另一個JUnit測試類運行JUnit測試類
- 22. 運行Eclipse插件的測試與JMockit和JUnit 3
- 23. 使用@SpringApplicationConfiguration進行JUnit測試自動啓動作業
- 24. 使用Eclipse進行單元測試 - JUNIT
- 25. 在Eclipse中提交之前自動運行JUnit測試
- 26. 啓動時出現IllegalStateException Spring JUnit測試
- 27. 如何從命令行運行Eclipse java JUnit測試套件? (windows)
- 28. 使用JUnit測試樹實現
- 29. JUnit測試java eclipse
- 30. 並行運行JUnit測試
請問我的答案'Eclipse如何實際運行測試'http://stackoverflow.com/a/7896628/1836幫助? –
我曾看過那篇文章,這是什麼讓我這麼遠。我已經能夠通過實現ITestReference,使用internal_kind擴展點以及解開一堆內部類來獲得它的工作。但是,這似乎比它應該更復雜!爲什麼RemoteTestRunner只有一個參數來指定junit亞軍!? – ekj