您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
Junit與Mockito依賴沖突問題解決
作者:Juude的博客 發(fā)布時間:[ 2017/3/6 11:45:56 ] 推薦標簽:單元測試 單元測試工具

  問題
  在使用mockito和junit進行單元測試時候,編譯出現(xiàn)了以下的錯誤:
  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.
  分析
  根據(jù)錯誤信息的網址,發(fā)現(xiàn)又這樣的說明
  Gradle build will fail if the main APK and the test APK use the same library (e.g. Guava) but in different versions.
  即引用了相同庫的不同版本導致的編譯不過。
  再通過執(zhí)行./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版本引起的問題
  解決方案
  根據(jù)錯誤提示,將junit版本降級或者mockito版本升級都可以,這里因為mockito2.0以后才使用hamcrest1.3版本,且mockito2.0還是beta的,將junit從4.12降級為4.10即可解決這個問題。

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd