简体   繁体   中英

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

For my Eclipse plugin project, I have defined the following target platform:

<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). 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:

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

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

How can you be compiling and launching your JUnit tests if JUnit is not part of the target platform? The first thing that you need to do is add org.junit and org.junit4 bundles to the target platform. 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.

Typically, you simply do not include the tests in the final RCP app or update site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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