Gradle是一個(gè)基于A(yíng)pache Ant和Apache Maven概念的項(xiàng)目自動(dòng)化建構(gòu)工具。拋棄了基于XML的各種繁瑣配置--易用和顏值很重要!
前提:JDK環(huán)境。
配置Gradle環(huán)境:官網(wǎng)上有多種安裝配置方法,不怕折騰的可以嘗試Gradle Wrapper、SDKMAN等方法。這里采用常規(guī)的Install manually方法即可,與JDK的配置方法相似:
下載zip > 解壓 > 配置環(huán)境變量Gradle_HOME、PATH在IntelliJ IDEA中創(chuàng)建Gradle工程:
File > New > Project > Gradle > Next...

Paste_Image.png


Paste_Image.png
- Gradle配置文件
將工程所需的依賴(lài)包都寫(xiě)到build.gradle文件中,IntelliJ IDEA會(huì)自動(dòng)加載。
dependencies {
compile 'org.jsoup:jsoup:1.10.2'
compile 'com.jayway.jsonpath:json-path:2.2.0'
compile 'commons-codec:commons-codec:1.10'
compile 'commons-dbutils:commons-dbutils:1.6'
compile 'mysql:mysql-connector-java:6.0.6'
compile 'com.google.inject:guice:4.1.0'
compile 'velocity:velocity:1.4'
testCompile 'org.uncommons:reportng:1.1.4'
testCompile 'org.testng:testng:6.0.1'
}
test{
useTestNG(){
suites(file('src/test/resources/testng.xml'))
}
options {
listeners << 'org.uncommons.reportng.HTMLReporter'
listeners << 'org.uncommons.reportng.JUnitXMLReporter'
}
}
FAQ
- ReportNG相關(guān)依賴(lài)
gradle test執(zhí)行測(cè)試用例時(shí),報(bào)錯(cuò),執(zhí)行g(shù)radle test --info或在...\IdeaProjects\APITest\build\reports\tests\test\index.html文件查看
Caused by: java.lang.ClassNotFoundException: com.google.inject.Injector
Caused by: java.lang.ClassNotFoundException: org.apache.velocity.context.Context
Solution:
guice、velocity都是ReportNG相關(guān)依賴(lài),如果不添加會(huì)報(bào)錯(cuò),上面的build.gradle中已添加。