我的RCP是在3.x Eclipse上创建的,现在使用兼容层在4.x上。
这是我的设置:我有两个插件:xyz-plugin
和xyz-rcp-plugin
。我的RCP应用程序由这两个插件组成。我有一个测试片段(xyz-test
),其主机插件是xyz-plugin
并包含SWTBot测试。我的产品配置指向xyz-rcp-plugin
的plugin.xml中定义的应用程序。
当我通过Eclipse运行SWTBot测试时,一切正常。我将它指向Main选项卡上的正确应用程序,它会启动正确的应用程序。
当我尝试通过Maven(使用mvn integration-test
)运行它时,在启动用于测试的UI的命令之后,没有UI打开,它只是报告说有测试失败但它实际上甚至没有到达阶段用于测试我的案例。
我觉得这种情况正在发生,因为我的测试片段只有xyz-plugin
作为主机,因此知道它的依赖性,但应用程序实际上包含在xyz-rcp-plugin
中,所以我猜它没有带来插件进入测试工作区。实际上,当我省略pom文件中的<application>
配置时,测试运行;它简单地启动默认的Eclipse SDK。
那么如果带有应用程序的插件不是测试插件的依赖项,我如何让SWTBot测试运行我的应用程序?
下面是我的测试片段的pom文件,
<?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>
答案 0 :(得分:5)
Tycho不会自动将定义配置的<application>
的包添加到测试运行时 - 您需要手动确保包含此包。
执行此操作的一种方法是在测试项目的pom.xml中指定额外的依赖项。通过这种方式,您可以将捆绑包甚至整个功能(一如既往地,包括传递依赖项)添加到测试运行时。
示例pom.xml片段:
<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>