您的位置:软件测试 > 开源软件测试 > 开源单元测试工具 > junit
Junit与Mockito依赖冲突问题解决
作者:Juude的博客 发布时间:[ 2017/3/6 11:45:56 ] 推荐标签:单元测试 单元测试工具

  问题
  在使用mockito和junit进行单元测试时候,编译出现了以下的错误:
  Conflict with dependency 'org.hamcrest:hamcrest-core'. Resolved versions for app (1.1) and test app (1.3) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
  分析
  根据错误信息的网址,发现又这样的说明
  Gradle build will fail if the main APK and the test APK use the same library (e.g. Guava) but in different versions.
  即引用了相同库的不同版本导致的编译不过。
  再通过执行./gradlew :app:dependencies查看依赖,得到以下的返回信息:
  testCompile - Classpath for compiling the test sources.
  +--- junit:junit:4.12
  | --- org.hamcrest:hamcrest-core:1.3
  --- org.mockito:mockito-core:1.9.5
  +--- org.hamcrest:hamcrest-core:1.1 -> 1.3
  --- org.objenesis:objenesis:1.0
  可以看到junit和mockito分别引用了 hamcrest-core 的1.3和1.1版本引起的问题
  解决方案
  根据错误提示,将junit版本降级或者mockito版本升级都可以,这里因为mockito2.0以后才使用hamcrest1.3版本,且mockito2.0还是beta的,将junit从4.12降级为4.10即可解决这个问题。

软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd