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

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

public class TushengInfo {

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

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

        List 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"},
        };
    }

}

你可能感兴趣的:(三、创建接口实例,编写测试用例)