接口测试3-4使用csv进行接口测试

参照前面的例子

向URL发送corpid和corsecret2个参数,可以获取正确的tokenid
https://qyapi.weixin.qq.com/cgi-bin/gettoken

数据

场景:
* id 有 secret没有
* id没有 select有
* id 错误 secret错误
* id 正确 secret错误
* id 错误 secret正确
* id 正确 secret正确
数据如下
corpid,corsecret,statuscode,errcode,
1,,200,41004,
,afkjl,200,41002,
3,ffljin,200,40013,
正确id,jkjk,200,40001,
bbn,正确secret,200,41002,
正确id,正确secret,200,0,40013

测试脚本

#java
package date89;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import testdata.CsvReader;

import java.io.IOException;

import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;

import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.urlEncodingEnabled;
import static org.junit.Assert.assertTrue;

public class DataDriverForToken {
    @DataProvider(name = "csv")
    public Object[][] testCsvData() throws IOException{
        return CsvReader.ggetTestData("src/test/java/testdata/testforpeople.csv");
    }

    @Test(dataProvider = "csv")
    public void getToken(String corpID,String corpSecret,String statusCode,String expectErrcode){//

        String url_token = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
        io.restassured.response.Response res = given().param("corpid",corpID).param("corpsecret",corpSecret).get(url_token);
        String resErrCode = res.getBody().jsonPath().getString("errcode");
        Integer resStatusCode = res.getStatusCode();
        assertThat(resErrCode,equalTo(expectErrcode));
        Integer expectStatusCode;
        try{
            expectStatusCode = Integer.parseInt(statusCode);
            assertThat(resStatusCode,equalTo(expectStatusCode));
        }catch (NumberFormatException e){
            e.printStackTrace();
        }
        //System.out.println(res.prettyPeek());
    }
}
posted on 2018-08-15 12:52  singleSpace  阅读(501)  评论(0编辑  收藏  举报