3

I´m running UI tests for an RCP application using SWTBot, which works fine while launching the tests in the eclipse IDE. Now I want to run the tests in maven, which also works so far. Unfortunately, through the dependency chain org.eclipse.swtbot.eclipse.finder --> org.eclipse.ui.editors --> org.eclipse.ui.ide the org.eclipse.ui.ide is also present in the application that runs the tests. With this bundle some unexpected menu items are present and the bundle should be excluded in the test runtime. How could this be achieved?

While running the tests in eclipse I simply exclude the org.eclipse.ui.ide bundle in the SWTBot Test launch configuration and everything works as expected.

Alexander Hansen
  • 813
  • 8
  • 14

1 Answers1

5

The dependency chain org.eclipse.swtbot.eclipse.finder --> org.eclipse.ui.editors --> org.eclipse.ui.ide contains an optional link: the first bundle only requires the second bundle via an optional import of the package org.eclipse.ui.texteditor. This is why you can remove the o.e.ui.ide bundle from the test runtime launched from Eclipse, and o.e.swtbot.eclipse.finder will still work.

Under normal circumstances, you could achieve the same in Tycho's test runtime by making sure that the optional dependency is not in the target platform:

<plugin>
   <groupId>org.eclipse.tycho</groupId>
   <artifactId>target-platform-configuration</artifactId>
   <version>${tycho-version}</version>
   <configuration>
      <filters>
         <filter>
            <type>eclipse-plugin</type>
            <id>org.eclipse.ui.ide</id>
            <removeAll />
         </filter>
      </filters>
   </configuration>
</plugin>

But here is why this doesn't work in your particular case: When you use the UI test harness (useUIHarness=true), Tycho unconditionally adds the bundle org.eclipse.ui.ide.application as extra requirement to your test runtime. That bundle has a non-optional requirement to org.eclipse.ui.ide, so with the target platform configuration above, you'll get a "cannot resolve dependency" error complaining about an unsatisfied constraint of org.eclipse.ui.ide.application.

So, I don't think that there is a solution in your case – but I consider this a bug in Tycho. The SWT bot tests run in Eclipse, so they should also run in Tycho. Obviously, Eclipse doesn't need the org.eclipse.ui.ide.application bundle (or otherwise it would have stopped working when you de-selected the org.eclipse.ui.ide bundle), so Tycho shouldn't need it either. Please file a bug report for Tycho and attach a minimal sample project that reproduces the problem, so that I can fix this.

oberlies
  • 11,503
  • 4
  • 63
  • 110
  • Unfortunately this doesn´t solve the problem, the dependency is not optional - `org.eclipse.swtbot.eclipse.finder` provides the testing capabilities for editors, views and the workbench which is also the reason I cant remove the direct dependency. But big thanks for the answer, I think this filter feature might be handy in other situations and I didn´t knew about it before. – Alexander Hansen Sep 10 '12 at 11:25
  • I got the dependency resolution error. I think it would be cool to give the dependency a scope like a maven dependency can have one. I even tried to reintroduce it as a maven dependency, use pomConsider and set the scope to `provided` which still results in the dependency resolution error. – Alexander Hansen Sep 10 '12 at 12:24
  • FYI: [Igor's p2 browser](https://github.com/ifedorenko/p2-browser) is a great tool for analysing transitive p2/OSGi dependencies. It even launches directly from the linked site. – oberlies Sep 10 '12 at 13:39
  • @CodeSeavers: Thanks for testing my original answer - I now figured out why it didn't work and edited the answer accordingly. – oberlies Sep 10 '12 at 14:10
  • Great, thanks! For now I rewrote the test so it works in the CI (maven) environment and will file a bug as soon as I find the time to compile the sample project – Alexander Hansen Sep 10 '12 at 14:30