junit - 我需要在Eclipse RCP Tycho项目中使用Mockito和JUnit哪些依赖项

标签 junit osgi tycho hamcrest tycho-surefire-plugin

这是我当前的测试片段:

<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方法来解决依赖关系:

<pomDependencies>consider</pomDependencies>

上面的JUnit版本是我能找到的唯一一个,它打包成一个捆绑包。

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

我的常见问题是:
  • 来自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创建自己的包。

    最佳答案

    我发现Eclipse Orbit的JUnit,Hamcrest和Mockito的包装器捆绑在一起工作得很好。

    对于(当前)最新的Orbit版本,其中包括JUnit 4.11,Hamcrest 1.1(1.3版中具有Hamcrest Core)和Mockito 1.8.4,只需在您的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 doesn't take these into account(并且Tycho使用p2进行依赖关系解析),因此您需要为片段的依赖关系解析(使用Mockito)提供额外的提示:

    <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的导入。

    关于junit - 我需要在Eclipse RCP Tycho项目中使用Mockito和JUnit哪些依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18122834/

    相关文章:

    java - JSF 支持 Bean 单元测试

    java - colver中的 'true branch executed'和 'branch executed'有什么不同?

    java - OSGi ( Felix ) 额外的 system.bundle 导出

    java - 在 OSGi 包中包含额外的资源

    eclipse - osgi.os 属性的 "win32"与 "win64"

    java - 将单元测试标记为 JUnit 中的预期失败

    java - Junit 测试中的模拟错误 UnfinishedStubbingException

    java - 使用 Tycho 解决对包 sun.misc 的依赖

    java - CompilationParticipant 包是否可用于 headless PDE 构建?

    eclipse-plugin - 如何将 jar 非 osgi jar 文件添加为 eclipse 插件的依赖项?