Which dependencies do I need to use Mockito and JUnit in an Eclipse RCP Tycho project

前端 未结 1 1560
情歌与酒
情歌与酒 2021-02-20 14:18

This is my current test fragment:

eclipse-test-plugin


    <         


        
相关标签:
1条回答
  • 2021-02-20 14:40

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

    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>
    

    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>
    

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

    0 讨论(0)
提交回复
热议问题