• 接口测试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());
        }
    }
    
  • 相关阅读:
    zabbix 组信息
    perl tk说明
    perl tk说明
    haproxy ssl相关配置
    haproxy ssl相关配置
    haproxy 关闭ssl 3.0 加密
    haproxy 关闭ssl 3.0 加密
    【华为敏捷/DevOps实践】4. 如何从Excel做项目管理的方式中走出来
    【华为云实战开发】13.如何在云端快速搭建python网站
    【华为云实战开发】12.如何在云端快速开展Swagger接口测试
  • 原文地址:https://www.cnblogs.com/csj2018/p/9480788.html
Copyright © 2020-2023  润新知