2

从命令行运行测试时,如何在非 ui 线程中运行 Eclipse JUnit 插件测试?在启动配置对话框中,我可以取消选中“在 UI 线程中运行”复选框,但是在命令行上运行插件测试时如何执行此操作?

编辑:似乎org.eclipse.pde.junit.runtime.nonuithreadtestapplicationPDE 启动在非 UI 线程中运行测试时使用的是什么,但是当我尝试使用它时,我得到“找不到参数'-port'”:

加载记录器配置:c:\work\dev\tooticki\core\ide\eclipse\plugins\com.iar.ide.tests\logging.properties
23:42:51,349 [main] INFO ew - 启动应用程序:com.iar.ew.Application 类
线程“WorkbenchTestable”java.lang.IllegalArgumentException 中的异常:错误:未指定参数“-port”
    在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:303)
    在 org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.init(RemotePluginTestRunner.java:83)
    在 org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:61)
    在 org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.runTests(NonUIThreadTestApplication.java:23)
    在 org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(WorkbenchTestable.java:71)
    在 java.lang.Thread.run(Thread.java:619)
4

3 回答 3

1

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

运行 PDE 测试的 ant 任务有两个目标,core-testui-test,分别用于无头测试和 UI 测试。有一篇关于Eclipse 测试框架的文章有更多细节,但基本上你可以选择相关的目标,只要你的测试代码不需要访问 UI,你的测试就会在 core-test 目标下运行。您可能还会发现这篇关于 PDE 和 Ant 的Eclipse Corner文章很有帮助

如果您通过其他方式调用测试。您仍然可以查看 PDE ant 任务的来源,以了解它们如何设置环境

于 2009-09-30T07:20:15.360 回答
1

创建一个从 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-testtarget 而不是ui-testor来运行测试core-test

祝你好运!

于 2010-09-30T17:00:39.610 回答
0

显然,org.eclipse.pde.junit.runtime.nonuithreadtestapplication需要一个专门的测试结果监听器。本文介绍了如何执行此操作。

于 2010-10-01T05:24:24.283 回答