【问题标题】:Running Eclipse Plug-in tests in non-ui thread在非 ui 线程中运行 Eclipse 插件测试
【发布时间】:2009-09-29 21:00:28
【问题描述】:

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

编辑:似乎org.eclipse.pde.junit.runtime.nonuithreadtestapplication 是 PDE 启动在非 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)

【问题讨论】:

    标签: eclipse junit eclipse-pde


    【解决方案1】:

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

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

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

    【讨论】:

    • 不,我没有使用 PDE ant 目标。我正在直接调用我的产品启动器。
    • 在这种情况下,您可以复制蚂蚁任务使用的处理,请参阅我的答案中的源链接
    【解决方案2】:

    创建一个从 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 运行测试。

    祝你好运!

    【讨论】:

      【解决方案3】:

      显然,org.eclipse.pde.junit.runtime.nonuithreadtestapplication 需要一个专门的测试结果监听器。 this article 中描述了如何执行此操作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-12-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-25
        • 1970-01-01
        • 2011-01-23
        相关资源
        最近更新 更多