5

My RCP was created on a 3.x Eclipse and is now on 4.x using the compatibility layer. This is the setup that I have: I have two plugins: xyz-plugin and xyz-rcp-plugin. My RCP application is composed of these two plugins. I have a Test fragment (xyz-test) whose host plugin is xyz-plugin and contains SWTBot tests. My product configuration points to the application defined in the plugin.xml of xyz-rcp-plugin.

When I run the SWTBot Test via Eclipse, it all works ok. I point it to the correct application on the Main tab and it launches the correct one.

When I try to run it via Maven (using mvn integration-test), after the command to launch the UI for testing, no UI opens and it just reports saying there are test failures but it never actually even reaches the stage for testing my cases.

I feel this is happening because my test fragment only has xyz-plugin as its host and so knows its dependency but the application is actually contained in xyz-rcp-plugin so I am guessing it doesn't bring that plugin into the testing workspace. In fact, the test runs when I omit the <application> configuration in my pom file; it simple launches the default which is the Eclipse SDK.

So but how can I make the SWTBot test run my application, if the plugin with the application is not a dependency of the test plugin?


Below is my pom file for the test fragment,

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.xyz</groupId>
        <artifactId>all</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <artifactId>com.xyz.test</artifactId>
    <packaging>eclipse-test-plugin</packaging>

    <properties>
        <ui.test.vmargs></ui.test.vmargs>
    </properties>

    <profiles>
        <profile>
            <id>macosx</id>
            <activation>
                <os>
                    <family>mac</family>
                </os>
            </activation>
            <properties>
                <ui.test.vmargs>-XstartOnFirstThread</ui.test.vmargs>
            </properties>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-surefire-plugin</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                    <useUIHarness>true</useUIHarness>
                    <useUIThread>false</useUIThread>
                    <product>com.xyz.rcp.product</product>
                    <application>com.xyz.rcp.Application</application>
                    <argLine>${ui.test.vmargs}</argLine>
                    <dependencies>
                        <dependency>
                            <!-- explicit dependency is only needed because SWTbot brings its 
                                own hamcrest bundle which conflicts with the one from junit in the eclipse 
                                platform -->
                            <type>p2-installable-unit</type>
                            <artifactId>org.hamcrest</artifactId>
                            <version>0.0.0</version>
                        </dependency>
                    </dependencies>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-xyz</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <excludeTransitive>true</excludeTransitive> 
                            <includeTypes>tar.gz</includeTypes>
                            <outputDirectory>${project.build.directory}/work</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
oberlies
  • 11,503
  • 4
  • 63
  • 110
nbz
  • 3,806
  • 3
  • 28
  • 56

1 Answers1

5

Tycho does not automatically add the bundle defining the configured <application> to the test runtime - you need to manually ensure that this bundle is included.

One way to do this is to specify extra dependencies in the pom.xml of the test project. In this way, you can add bundles or even entire features (as always, including transitive dependencies) to the test runtime.

Example pom.xml snippet:

<plugin>
  <groupId>org.eclipse.tycho</groupId>
  <artifactId>target-platform-configuration</artifactId>
  <version>${tycho-version}</version>
  <configuration>
    <dependency-resolution>
      <extraRequirements>
        <requirement>
          <type>eclipse-plugin</type>
          <id>xyz-rcp-plugin</id>
          <versionRange>0.0.0</versionRange>
        </requirement>
      </extraRequirements>
    </dependency-resolution>
  </configuration>
</plugin>
oberlies
  • 11,503
  • 4
  • 63
  • 110
  • Well you did answer my question... but it doesn't seem to have helped. It still keeps failing silently... – nbz Feb 20 '13 at 14:50
  • yes I am beginning to wonder the same thing. Let me try that and I will update the post here too. Thanks for your help though. I will vote up! – nbz Feb 20 '13 at 15:11
  • I noticed that I am getting a bunch of these errors on all the swt bundles - Missing required capability Require-Capability: osgi.ee – nbz Feb 21 '13 at 14:03
  • 1
    So it worked! I had to make a change in the parent pom file... I don't have very much maven experience so maybe this is something everyone already knows, but I had to change the order of my modules - so I had to put my rcp module before the test module. Maybe you can add that as a 'Do Not Forget' on your answer (unless this is something very basic hehe) Thanks! – nbz Mar 05 '13 at 00:30
  • I've updated the solution to avoid the need to manually order the modules. – oberlies Nov 29 '13 at 13:40
  • 1
    In the meanwhile (since Tycho 0.21.0), manual changes to the build order by re-ordering modules in the parent POM no longer have an effect on the build result. Instead, you need to configuration described in the answer to solve the problem. – oberlies Feb 16 '15 at 10:20