美文网首页
三、创建接口实例,编写测试用例

三、创建接口实例,编写测试用例

作者: 木沐__ | 来源:发表于2018-02-04 12:01 被阅读0次

请求方法封装后,就需要为每个接口编写实例方法

public class TushengInfo {

    Request request = new Request();
    String domain = "tushengAddress";

    public JSONObject activeAccount(String realName, String expressInc){
        List<NameValuePair> param = new ArrayList<>();
        param.add(new BasicNameValuePair("realName",realName));
        param.add(new BasicNameValuePair("expressInc",expressInc));

        List<NameValuePair> header = new ArrayList<>();
        header.add(new BasicNameValuePair("Authorization","18051df6-1049-4af2-bc55-625e84965e3e"));

        JSONObject response = request.post(domain,"/user/activation",param,header);

        return response;
    }

}

然后编写对应接口的测试用例
@BeforeMethod等TestNG注解的介绍具体见TestNG进阶

public class ActiveAccount{
    private TushengInfo tushengInfo;

    @BeforeMethod
    public void init(){
        tushengInfo = new TushengInfo(client,request);
    }

    @Test(dataProvider = "activeData")
    public void activeAccount(String realName, String expressInc, String expectResultCode){

        JSONObject response=tushengInfo.activeAccount(realName,expressInc);
        String resultCode = response.getString("resultCode");
        Assert.assertEquals(resultCode,expectResultCode);
    }

    @DataProvider
    public Object[][] activeData(){
        return new Object[][]{
                {"测试","顺丰快递","0"},
        };
    }

}

相关文章

网友评论

      本文标题:三、创建接口实例,编写测试用例

      本文链接:https://www.haomeiwen.com/subject/bdtqzxtx.html