在非 ui 线程中运行 Eclipse 插件测试
从命令行运行测试时,如何在非 ui 线程中运行 Eclipse JUnit 插件测试?在启动配置对话框中,我可以取消选中“在 UI 线程中运行”复选框,但是在命令行上运行插件测试时如何做到这一点?
编辑:似乎 org.eclipse.pde.junit.runtime.nonuithreadtestapplication 是 PDE 启动在非 UI 线程中运行测试时使用的内容,但是当我尝试使用它时,我得到“未找到参数“-port””:
Loading logger configuration: c:\work\dev\tooticki\core\ide\eclipse\plugins\com.iar.ide.tests\logging.properties 23:42:51,349 [main ] INFO ew - Starting application: class com.iar.ew.Application Exception in thread "WorkbenchTestable" java.lang.IllegalArgumentException: Error: parameter '-port' not specified at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:303) at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.init(RemotePluginTestRunner.java:83) at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:61) at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.runTests(NonUIThreadTestApplication.java:23) at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(WorkbenchTestable.java:71) at java.lang.Thread.run(Thread.java:619)
How do I run a Eclipse JUnit plug-in test in a non-ui thread when running the tests from the command-line? In the launch configuration dialog I can uncheck the checkbox "Run in UI thread", but how do I do that when running plug-in tests on the command-line?
EDIT: It seems as if org.eclipse.pde.junit.runtime.nonuithreadtestapplication
is what the PDE launch uses when running tests in a non-UI thread, but when I try using that, I get "parameter '-port' not found":
Loading logger configuration: c:\work\dev\tooticki\core\ide\eclipse\plugins\com.iar.ide.tests\logging.properties 23:42:51,349 [main ] INFO ew - Starting application: class com.iar.ew.Application Exception in thread "WorkbenchTestable" java.lang.IllegalArgumentException: Error: parameter '-port' not specified at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:303) at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.init(RemotePluginTestRunner.java:83) at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:61) at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.runTests(NonUIThreadTestApplication.java:23) at org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(WorkbenchTestable.java:71) at java.lang.Thread.run(Thread.java:619)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您说从命令行运行测试时,您的意思是调用 PDE ant 目标吗?
运行 PDE 测试的 ant 任务有两个目标,core-test 和 ui-test 分别用于无头测试和 UI 测试。有一篇关于 Eclipse 测试框架的文章 提供更多详细信息,但本质上您只需选择相关目标,只要您的测试代码不需要访问 UI,您的测试就会在核心测试目标下运行。您还可以找到这篇关于 PDE 和 Ant 的 Eclipse Corner 文章
如果您通过其他方式调用测试,会有帮助。您仍然可以查看 PDE ant 任务的来源,以了解它们如何设置环境
When you say running the tests from the command-line, do you mean by invoking the PDE ant goals?
The ant task to run the PDE tests has two targets, core-test and ui-test for testing headlessly and with the UI respectively. There's an article on the Eclipse Test Framework with more details, but essentially you can just pick the relevant target and as long as your code under test doesn't need access to the UI your tests will run under the core-test target. You may also find this Eclipse Corner article on PDE and Ant helpful
If you are invoking the tests by another means. You can still have a look at the source of the PDE ant tasks to understand how they setup the environment
创建一个从 org.eclipse.pde.internal.junit.runtime.UITestApplication 扩展的新应用程序类:
由于依赖性限制,我认为您必须将 EclipseTestRunner 按原样从 org.eclipse.test 插件复制到您的插件中。
将新应用程序添加到您的plugin.xml中:
将新部分添加到org.eclipse.test/library.xml中:
完成此操作后,您可以使用
nonui-thread-ui-test
运行测试目标而不是ui-test
或core-test
。祝你好运!
Create a new application class that extends from org.eclipse.pde.internal.junit.runtime.UITestApplication:
I think you must copy EclipseTestRunner as is from org.eclipse.test plug-in into your plug-in due to dependency restrictions.
Add a new application into your plugin.xml:
Add a new section into org.eclipse.test/library.xml:
After this is done, you can run your tests using
nonui-thread-ui-test
target instead ofui-test
orcore-test
.Good luck!
显然,org.eclipse.pde.junit.runtime.nonuithreadtestapplication 需要一个专用的测试结果监听器。 本文中描述了如何执行此操作。
Apparently,
org.eclipse.pde.junit.runtime.nonuithreadtestapplication
needs a dedicated test results listener. How to do this is described in this article.