简体   繁体   English

在Eclipse Indigo中运行JUnit插件测试的正确目标平台?

[英]Right target platform for running JUnit plugin tests in Eclipse Indigo?

For my Eclipse plugin project, I have defined the following target platform: 对于我的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"/>
...

My plugin has JUnit plugin tests (in the same plugin). 我的插件有JUnit插件测试(在同一个插件中)。 If I try to run them with a JUnit launch config ( org.eclipse.platform.ide ), I get the following console messages about junit , and an exception: 如果我尝试使用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.

and

!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)

With the default JDT installation, the unit test runs fine, it's just that I want to define a proper target platform for a Hudson-build. 使用默认的JDT安装,单元测试运行正常,只是我想为Hudson-build定义一个合适的目标平台。 Needless to say, I tried adding dependencies on the two offending platforms in various places, to no avail. 毋庸置疑,我尝试在各个地方的两个违规平台上添加依赖项,但无济于事。

Update : Whoops, I confused this with another set of tests; 更新 :哎呀,我把它与另一组测试混淆了; these here are not headless but workbench-tests. 这些不是无头但是工作台测试。

Another oddity is that sometimes I won't see this error when running the test for the first time after switching to the default Eclipse platform and back to mine. 另一个奇怪的是,在切换到默认Eclipse平台并返回我的第一次运行测试后,有时我不会看到此错误。 Odd. 奇。

I don't like to blow my own horn here, but the only workaround I could come up with now (after another few hours of experimentation) is setting the launch-config to "all workspace and enabled target plugins" instead of either using a feature or plugin-based launch. 我不喜欢在这里吹响自己的号角,但我现在能够想出的唯一解决办法(经过几个小时的实验)将launch-config设置为"all workspace and enabled target plugins"而不是使用功能或基于插件的启动。 I think this indicates that there is something fishy in the plugin-resolution process which Eclipse gets right by default, but not when you start restricting the available features/plugins. 我认为这表明在插件解析过程中有一些可疑的东西,默认情况下Eclipse是正确的,但是当你开始限制可用的功能/插件时却没有。

With that change, it seems to reliably work both within Eclipse and Buckminster (leaving the target platform unchanged(!) from the problematic setup in the original question). 通过这种改变,似乎可以在Eclipse和Buckminster中可靠地工作(使目标平台保持不变(!)不受原始问题中有问题的设置的影响)。 So I conclude that the target platform is in principle correct, it must have been something about the launch. 所以我得出结论,目标平台原则上是正确的,它一定是关于发布的东西。

Thanks for everyone's (@andrew-eisenberg, @PaulWebster at least) input! 谢谢大家(@ andrew-eisenberg,至少@PaulWebster)的输入!

How can you be compiling and launching your JUnit tests if JUnit is not part of the target platform? 如果JUnit不是目标平台的一部分,您如何编译和启动JUnit测试? The first thing that you need to do is add org.junit and org.junit4 bundles to the target platform. 您需要做的第一件事是将org.junit和org.junit4包添加到目标平台。 Since it looks like you are doing a feature-based target platform, you may need to create a custom feature for these bundles. 由于您看起来正在使用基于功能的目标平台,因此您可能需要为这些捆绑包创建自定义功能。

Second, since it is unlikely that you want to ship your tests with your plugin, you probably want to follow the standard Eclipse practice of separating your tests into a *..tests plugin. 其次,由于您不太可能希望使用插件发布测试,因此您可能希望遵循将测试分离为* .. tests插件的标准Eclipse实践。

Typically, you simply do not include the tests in the final RCP app or update site. 通常,您只是不在最终的RCP应用程序或更新站点中包含测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM