在熟悉hutool工具包時出現的關于Assert.assertEquals()的報錯及其解決方法
前提(也是主要問題)
用testCompile導入junit4.12
build.gradle文件
plugins {
id 'java'
}
group 'com.sukn'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
//1.優先查找本地maven庫,性能最好
mavenLocal()
//2.其次查找aliyun maven庫
maven{
url'http://maven.aliyun.com/nexus/content/groups/public/'
}
//3.最后查找maven中央庫
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'cn.hutool:hutool-all:5.2.1'
}
在IDEA的自動提示下
(有問題的地方Alt+Enter)自動導入包cn.hutool.core.lang.Assert后,assertEquals報錯
點進去Assert看了下發現
Assert中并無assertEquals()]方法
后面看了才知道導錯包
應該導org.junit.Assert而不是圖中的cn.hutool.core.lang.Assert,但又出現了問題Cannot resolve symbol 'Assert‘
本來以為是junit依賴沒導進來
但是看了下External Libraries
里面Assert安安靜靜的躺在那里
網上找了下,很多人都說要在org.junit.Assert前面加個static
嘗試后還是沒用
突然看到IDEA的自動提示中有個Add library ‘Gradle: junit:junit:4.12’ to classpath 點擊之后就解決了,但是org.junit.Assert前面的static也沒了
本來以為這樣就結束了
沒想到等我一更新下gradle的依賴導入后,問題又出現了,一下子又回到解放前
之后一直想不懂到底是哪里出了問題
網上也沒有很好的解決方案,只能自己一步步嘗試,最后想到了junit的依賴導入方式,感覺可以用compile代替下testCompile試試,最后終于好了。
build.gradle文件
plugins {
id 'java'
}
group 'com.sukn'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
//1.優先查找本地maven庫,性能最好
mavenLocal()
//2.其次查找aliyun maven庫
maven{
url'http://maven.aliyun.com/nexus/content/groups/public/'
}
//3.最后查找maven中央庫
mavenCentral()
}
dependencies {
compile group: 'junit', name: 'junit', version: '4.12'
compile 'cn.hutool:hutool-all:5.2.1'
}
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持html5模板網。
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!