java接口自动化测试框架搭建
生活随笔
收集整理的這篇文章主要介紹了
java接口自动化测试框架搭建
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一.restassured進行接口請求
1.get方法請求接口并獲取返回response對象
import static io.restassured.RestAssured.given; import io.restassured.response.Response;public class RestDemo {@Testpublic void testGetHtml(){Response response = given().log().all().param("wd", "豆瓣").when().get("http://www.baidu.com/").then().log().all().statusCode(200).extract().response();} given():一次網絡請求所需要的條件都寫在這里,頭信息、query參數 when():觸發條件 then():斷言 extract():提取返回值2.post方法請求接口并獲取返回response對象
import static io.restassured.RestAssured.given; import io.restassured.response.Response;public class RestDemo {@Testpublic void testGetHtml(){Response response = given().log().all().body().param("wd", "豆瓣").when().post("http://www.baidu.com/").then().log().all().statusCode(200).extract().response();} given():一次網絡請求所需要的條件都寫在這里,頭信息、query參數 when():觸發條件 then():斷言 extract():提取返回值二.junit執行測試用例
1.新建Calculate類
package com.coke.util;public class Calculate {public int add(int a,int b){return a+b;}public int sub(int a,int b){return a-b;}public int mul(int a,int b){return a * b;}public int div(int a,int b){return a / b;}}2.在同一個包下新建CalculateTest類,然后便可在idea中運行
package com.coke.util; import org.junit.*; public class CalculateTest {@Testpublic void testAdd(){int result = new Calculate().add(1,2);Assert.assertEquals(3,result);}@Testpublic void testSub(){int result = new Calculate().sub(4,1);Assert.assertEquals(3,result);System.out.println("123");}@Testpublic void testDiv(){int result = new Calculate().div(8,2);Assert.assertEquals(4,result);} }總結
以上是生活随笔為你收集整理的java接口自动化测试框架搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android动态赋权限,安卓6.0以上
- 下一篇: 叉积求点到平面距离_用叉乘求法向量.do