我需要在Eclipse RCP Tycho项目中使用Mockito和JUnit哪些依赖项 [英] Which dependencies do I need to use Mockito and JUnit in an Eclipse RCP Tycho project

查看:129
本文介绍了我需要在Eclipse RCP Tycho项目中使用Mockito和JUnit哪些依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我当前的测试片段:

This is my current test fragment:

<packaging>eclipse-test-plugin</packaging>

<dependencies>
    <dependency>
        <groupId>org.junit</groupId>
        <artifactId>com.springsource.org.junit</artifactId>
        <version>4.7.0</version>
    </dependency>
</dependencies>

具有以下插件配置:

<plugin>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>tycho-surefire-plugin</artifactId>
    <version>${tycho.version}</version>
    <configuration>
        <dependencies>
            <dependency>
                <type>p2-installable-unit</type>
                <artifactId>org.eclipse.equinox.ds</artifactId>
            </dependency>
            <dependency>
                <type>p2-installable-unit</type>
                <artifactId>org.apache.felix.gogo.shell</artifactId>
            </dependency>
        </dependencies>
        <providerHint>junit47</providerHint>
        <argLine>-ea</argLine>
    </configuration>
</plugin>

并且我使用POM-first方法来解决依赖关系:

and I use the POM-first approach to resolve dependencies:

<pomDependencies>consider</pomDependencies>

上面的JUnit版本是我能找到的唯一一个,被打包为一个捆绑包.

The above JUnit Version is the only one I could find, that is packaged as a bundle.

问题是我找不到匹配项,该匹配项允许我在一个片段中一起使用JUnit和Mockito.

The problem is that I cannot find a match which allows me to use JUnit and Mockito together in a fragment.

我的常见问题是:

  • 来自Maven Central的Mockito-core需要Hamcrest 1.0-2.0,但JUnit捆绑包会导出4.7.0版的Hamcrest
  • Springsource存储库中没有junit-dep捆绑包
  • 当我添加另一个Hamcrest捆绑软件时,JUnit(4.7.0)和Hamcrest捆绑软件(1.3)导出的版本之间存在版本冲突

我想避免从JUnit,Hamcrest和Mockito创建自己的捆绑软件.

I would like to avoid creating my own bundle from JUnit, Hamcrest and Mockito.

推荐答案

我发现

I have found that the wrapper bundles of JUnit, Hamcrest, and Mockito from the Eclipse Orbit work well together.

对于(当前)最新的Orbit版本,其中包括JUnit 4.11,Hamcrest 1.1(1.3版中具有Hamcrest Core)和Mockito 1.8.4,只需将以下代码段添加到您的POM中:

For the (currently) latest Orbit release, which includes JUnit 4.11, Hamcrest 1.1 (with Hamcrest Core in version 1.3), and Mockito 1.8.4, just add the following snippet to your POM:

<repositories>
    <repository>
        <id>orbit-kepler</id>
        <url>http://download.eclipse.org/tools/orbit/downloads/drops/R20130517111416/repository/</url>
        <layout>p2</layout>
    </repository>
</repositories>

在Eclipse Orbit的包装器中,org.junit捆绑包导出包org.hamcrest.core的一部分.但是,Mockito需要org.hamcrest.core包的完整内容.为了防止在Mockito和JUnit捆绑包之间进行意外接线,将导出标记为必填属性.不幸的是, p2没有考虑到这些(而Tycho使用p2用于依赖关系解析),因此您需要为片段的依赖关系解析(使用Mockito)提供额外提示:

In the wrappers of the Eclipse Orbit, the org.junit bundle exports parts of the package org.hamcrest.core. Mockito however needs the complete content of the org.hamcrest.core package. In order to prevent accidental wiring between the Mockito and JUnit bundle, the export is marked with a mandatory attribute. Unfortunately, p2 doesn't take these into account (and Tycho uses p2 for dependency resolution), so you need to give the dependency resolution of your fragment (using Mockito) an extra hint:

<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>org.hamcrest</id>
                    <versionRange>0.0.0</versionRange>
                </requirement>
            </extraRequirements>
        </dependency-resolution>
    </configuration>
</plugin>

这可以确保在依赖关系解析期间使用org.hamcrest捆绑包,并且可以成功连接Mokito的导入.

This makes sure that the org.hamcrest bundle is used during dependency resolution, and that Mokito's imports can be wired successfully.

这篇关于我需要在Eclipse RCP Tycho项目中使用Mockito和JUnit哪些依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆