【问题标题】:Right target platform for running JUnit plugin tests in Eclipse Indigo?在 Eclipse Indigo 中运行 JUnit 插件测试的正确目标平台?
【发布时间】:2011-12-16 12:24:20
【问题描述】:

对于我的 Eclipse 插件项目,我定义了以下目标平台:

<location includeAllPlatforms="true" includeMode="slicer" includeSource="true" type="InstallableUnit">
  <unit id="org.eclipse.equinox.executable.feature.group" version="3.5.0.v20110530-7P7NFUFFLWUl76mart"/>
  <unit id="org.eclipse.rcp.sdk.id" version="3.7.1.M20110909-1335"/>
  <unit id="org.eclipse.jdt.feature.group" version="3.7.1.r371_v20110810-0800-7z8gFcoFMLfTabvKsR5Qm9rBGEBK"/>
  <unit id="epp.package.java" version="1.4.1.20110909-1818"/>
...

我的插件有 JUnit 插件测试(在同一个插件中)。如果我尝试使用 JUnit 启动配置 (org.eclipse.platform.ide) 运行它们,我会收到以下关于 junit 的控制台消息和一个异常:

!ENTRY org.eclipse.osgi 2 0 2011-12-16 13:00:35.206
!MESSAGE One or more bundles are not resolved because the following root constraints are not resolved:
!SUBENTRY 1 org.eclipse.osgi 2 0 2011-12-16 13:00:35.206
!MESSAGE Bundle reference:file:/Users/stolz/ws-bucky/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.eclipse.jdt.junit4.runtime_1.1.200.v20110505-0800.jar was not resolved.
!SUBENTRY 2 org.eclipse.jdt.junit4.runtime 2 0 2011-12-16 13:00:35.206
!MESSAGE Missing required bundle org.junit_4.7.0.
!SUBENTRY 1 org.eclipse.osgi 2 0 2011-12-16 13:00:35.207
!MESSAGE Bundle reference:file:/Users/stolz/ws-bucky/.metadata/.plugins/org.eclipse.pde.core/.bundle_pool/plugins/org.junit4_4.8.1.v20100525/ was not resolved.
!SUBENTRY 2 org.junit4 2 0 2011-12-16 13:00:35.207
!MESSAGE Missing required bundle org.junit_4.8.1.

!SUBENTRY 1 org.eclipse.osgi 2 0 2011-12-16 13:00:35.234
!MESSAGE Bundle org.junit4_4.8.1.v20100525 [219] was not resolved.
!SUBENTRY 2 org.junit4 2 0 2011-12-16 13:00:35.235
!MESSAGE Missing required bundle org.junit_4.8.1.

!ENTRY org.eclipse.core.net 1 0 2011-12-16 13:00:39.889
!MESSAGE System property http.nonProxyHosts has been set to local|*.local|169.254/16|*.169.254/16 by an external source. This value will be overwritten using the values from the preferences
Exception in thread "Plug-in Tests Runner" java.lang.IllegalArgumentException: Bundle "org.eclipse.jdt.junit4.runtime" not found. Possible causes include missing dependencies, too restrictive version ranges, or a non-matching required execution environment.
    at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.getClassLoader(RemotePluginTestRunner.java:77)
    at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.readPluginArgs(RemotePluginTestRunner.java:93)
    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.PlatformUITestHarness$1.run(PlatformUITestHarness.java:47)
    at java.lang.Thread.run(Thread.java:680)

使用默认的 JDT 安装,单元测试运行良好,只是我想为 Hudson 构建定义一个合适的目标平台。不用说,我尝试在各个地方添加对两个违规平台的依赖,但无济于事。

更新: 糟糕,我将此与另一组测试混淆了;这里的这些不是无头的,而是工作台测试。

另一个奇怪的是,有时我在切换到默认 Eclipse 平台并返回我的平台后第一次运行测试时不会看到此错误。奇怪。

【问题讨论】:

  • 你在用什么“他们用一个无头的 JUnit 启动配置”?您的意思是从命令行无头启动它们还是使用“无应用程序 - 无头模式”?
  • @PaulWebster 告诉我,测试根本不是无头的,而是工作台测试。我已经更新了问题。
  • 你的目标平台至少需要org.eclipse.rcp.feature.group、org.eclipse.platform.feature.group和org.eclipse.jdt.feature.group,对吧?
  • @PaulWebster 我添加了 rcp 和平台功能组,但行为(以及插件总数)没有改变。还要注意我在更新中提到的奇怪之处。

标签: eclipse junit eclipse-plugin


【解决方案1】:

我不喜欢在这里自吹自擂,但我现在能想到的唯一解决方法(经过几个小时的实验)是将启动配置设置为 "all workspace and enabled target plugins",而不是使用功能或基于插件的启动。我认为这表明在插件解析过程中存在一些问题,Eclipse 默认情况下是正确的,但在您开始限制可用功能/插件时却没有。

随着这一变化,它似乎在 Eclipse 和 Buckminster 中都能可靠地工作(使目标平台保持不变(!),而不是原始问题中的有问题的设置)。所以我的结论是目标平台原则上是正确的,一定是发布的问题。

感谢大家(至少@andrew-eisenberg,@PaulWebster)的投入!

【讨论】:

    【解决方案2】:

    如果 JUnit 不是目标平台的一部分,您如何编译和启动 JUnit 测试?您需要做的第一件事是将 org.junit 和 org.junit4 包添加到目标平台。由于看起来您正在开发基于功能的目标平台,因此您可能需要为这些捆绑包创建自定义功能。

    其次,由于您不太可能希望将测试与您的插件一起发布,您可能希望遵循标准 Eclipse 实践,将您的测试分离到一个 *..tests 插件中。

    通常,您只是不将测试包含在最终的 RCP 应用或更新站点中。

    【讨论】:

    • JUnit 是 JDT 的一部分(我依赖它)。所以原则上它就在那里。但我完全被版本号弄糊涂了:Eclipse 带来了 4.8.2,而 JDT 似乎依赖于 4.7.0。而且我还没有发现对 4.8.1 的依赖来自哪里。
    • 另一件事:由于我的项目还定义了一个功能(在启动配置中使用),我尝试在那里添加所需的插件,但也无济于事。对于刚刚发布 JUnit 的新功能,我希望看到相同的结果。它还担心它不可靠的可重现性,有时(在重置目标平台/工作区后)它会起作用。
    猜你喜欢
    • 2016-09-06
    • 1970-01-01
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    相关资源
    最近更新 更多