Rest-Assured新手入門(1)---環(huán)境搭建

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)境搭建成功,新手入門,輕拍。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容