这是我当前的测试片段:
<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。
我的常见问题是:
我想避免从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没有考虑到这些(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的导入。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句