Junit与Mockito依赖冲突问题解决

发表于:2017-3-06 11:41

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Juude的博客    来源:51Testing软件测试网采编

  问题
  在使用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即可解决这个问题。
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号