【问题标题】:How to add the plugin with my RCP application in the Tycho SWTBot test runtime如何在 Tycho SWTBot 测试运行时中使用我的 RCP 应用程序添加插件
【发布时间】:2014-11-17 17:18:26
【问题描述】:

我的 RCP 是在 3.x Eclipse 上创建的,现在使用兼容层在 4.x 上。 这是我的设置:我有两个插件:xyz-pluginxyz-rcp-plugin。我的 RCP 应用程序由这两个插件组成。我有一个测试片段 (xyz-test),它的主机插件是 xyz-plugin 并包含 SWTBot 测试。我的产品配置指向xyz-rcp-plugin的plugin.xml中定义的应用。

当我通过 Eclipse 运行 SWTBot 测试时,一切正常。我将它指向主选项卡上的正确应用程序,它会启动正确的应用程序。

当我尝试通过 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>

【问题讨论】:

  • 当您以调试模式 (-X) 运行构建时,Tycho 会告诉您哪些包在测试运行时中。
  • 我试过了......但我仍然不确定在哪里添加我的 rcp 插件作为依赖项

标签: eclipse testing eclipse-rcp tycho swtbot


【解决方案1】:

Tycho 不会自动将定义配置的 &lt;application&gt; 的包添加到测试运行时 - 您需要手动确保包含此包。

一种方法是在测试项目的 pom.xml 中指定额外的依赖项。通过这种方式,您可以将捆绑包甚至整个功能(一如既往,包括传递依赖项)添加到测试运行时。

示例 pom.xml sn-p:

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

【讨论】:

  • 嗯,你确实回答了我的问题......但它似乎没有帮助。它仍然默默地失败......
  • 是的,我开始怀疑同样的事情。让我试试,我也会在这里更新帖子。不过感谢您的帮助。我会投票!
  • 我注意到我在所有 swt 捆绑包上都收到了一堆这些错误 - 缺少所需的功能 Require-Capability: osgi.ee
  • 成功了!我必须在父 pom 文件中进行更改...我没有太多 maven 经验所以也许这是每个人都已经知道的,但我必须更改模块的顺序 - 所以我必须把我的 rcp测试模块之前的模块。也许您可以在答案中添加“不要忘记”(除非这是非常基本的内容,呵呵)谢谢!
  • 同时(自 Tycho 0.21.0 起),通过在父 POM 中重新排序模块来手动更改构建顺序不再对构建结果产生影响。相反,您需要按照答案中描述的配置来解决问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-16
  • 2014-10-19
  • 1970-01-01
  • 2018-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多