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

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

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