1.前期準(zhǔn)備
1.JDK 、 maven 、 Intellij IDEA
JDK及maven環(huán)境變量配置,請(qǐng)自行百度。
環(huán)境配置完成后,輸入
mvn -v
java -version
出現(xiàn)如下截圖,則環(huán)境配置成功

環(huán)境
2.新建項(xiàng)目添加依賴
2.1首先新建一個(gè)maven項(xiàng)目
進(jìn)入IDEA---File---New---Project---maven

maven1

maven2
2.2在pom.xml添加相關(guān)依賴
打開剛才建好的項(xiàng)目,結(jié)構(gòu)如圖所示:

Paste_Image.png
在pom.xml中添加rest-assurd、json-path、junit等相關(guān)依賴
如何添加,添加什么,請(qǐng)見github 文檔說明
<dependencies>
<!--rest assured相關(guān)-->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>xml-path</artifactId>
<version>3.0.3</version>
</dependency>
<!--junit-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
添加依賴后,IDEA會(huì)自動(dòng)下載需要的信息

Paste_Image.png
3.靜態(tài)導(dǎo)入
官方文檔中寫到:
In order to use REST assured effectively it's recommended to statically import methods from the following classes:
io.restassured.RestAssured.*
io.restassured.matcher.RestAssuredMatchers.*
org.hamcrest.Matchers.*
既然官方都建議我們靜態(tài)導(dǎo)入了,那就靜態(tài)導(dǎo)入。
import static io.restassured.RestAssured.*;
import static io.restassured.matcher.ResponseAwareMatcher.*;
import static org.hamcrest.Matchers.*;
新建一個(gè)class文件,靜態(tài)導(dǎo)入這些classes,如果文件不標(biāo)紅,則說明環(huán)境搭建成功:
以百度為例,一個(gè)簡單的demo如下:
public class Demo1 {
@Test
public void test_demo1(){
int statucecode = get("http://www.baidu.com/").statusCode();
assertEquals(200,statucecode);
}
}
ok,至此Rest-Assurd環(huán)境搭建成功,新手入門,輕拍。