在非 ui 线程中运行 Eclipse 插件测试

发布于 2024-08-06 02:30:40 字数 1153 浏览 3 评论 0原文

从命令行运行测试时,如何在非 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一桥轻雨一伞开 2024-08-13 02:30:40

当您说从命令行运行测试时,您的意思是调用 PDE ant 目标吗?

运行 PDE 测试的 ant 任务有两个目标,core-testui-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

雨巷深深 2024-08-13 02:30:40

创建一个从 org.eclipse.pde.internal.junit.runtime.UITestApplication 扩展的新应用程序类:

public class NonUIThreadTestApplication extends UITestApplication {
  public void runTests() {
    fTestableObject.testingStarting();
    try {
      EclipseTestRunner.run(Platform.getCommandLineArgs());
    } catch (IOException e) {
      e.printStackTrace();
    }
    fTestableObject.testingFinished();
  }
}

由于依赖性限制,我认为您必须将 EclipseTestRunner 按原样从 org.eclipse.test 插件复制到您的插件中。

将新应用程序添加到您的plugin.xml中:

<extension
         id="nonuithreadtestapplication"
         point="org.eclipse.core.runtime.applications">
  <application visible="false">
    <run class="com.my.test.NonUIThreadTestApplication" />
  </application>
</extension>

将新部分添加到org.eclipse.test/library.xml中:

<target name="nonui-thread-ui-test" description="Eclipse application used to launch UI plugin tests in a non-UI thread." depends="init">
  <antcall target="${launchTarget}">
    <param name="application" value="com.my.test.nonuithreadtestapplication" />
  </antcall>
</target>

完成此操作后,您可以使用nonui-thread-ui-test运行测试目标而不是 ui-testcore-test

祝你好运!

Create a new application class that extends from org.eclipse.pde.internal.junit.runtime.UITestApplication:

public class NonUIThreadTestApplication extends UITestApplication {
  public void runTests() {
    fTestableObject.testingStarting();
    try {
      EclipseTestRunner.run(Platform.getCommandLineArgs());
    } catch (IOException e) {
      e.printStackTrace();
    }
    fTestableObject.testingFinished();
  }
}

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:

<extension
         id="nonuithreadtestapplication"
         point="org.eclipse.core.runtime.applications">
  <application visible="false">
    <run class="com.my.test.NonUIThreadTestApplication" />
  </application>
</extension>

Add a new section into org.eclipse.test/library.xml:

<target name="nonui-thread-ui-test" description="Eclipse application used to launch UI plugin tests in a non-UI thread." depends="init">
  <antcall target="${launchTarget}">
    <param name="application" value="com.my.test.nonuithreadtestapplication" />
  </antcall>
</target>

After this is done, you can run your tests using nonui-thread-ui-test target instead of ui-test or core-test.

Good luck!

画▽骨i 2024-08-13 02:30:40

显然,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文