day27java接口自动化学习.png
1. 根据接口规范编写请求响应javabean
2. 根据接口规范编写测试类
3. 实例化请求javabean 进行设值
4. 根据接口规范对设值后的javabean进行转换格式 调用JSON.toJSONtring()
5. 根据接口规范声明请求路径
6. 调用httpTool工具类 调用 dopostjson 方法传入请求接口路径 json数据内容 编码格式
7. 声明变量保存执行接口请求后响应结果内容
8. 调用响应javabean保存响应结果使用json转对象方法 JSON.parseObject()
9. 添加断言,断言响应结果是否正确
package com.guoyasoft.aotutest001.javabean.signup;
/**
* @program: aotu-test
* @description:
* @author: Administrator
* @create: 2018-11-21 11:52
**/
public class SignUpRequest {
private String phone;
private String pwd;
private String rePwd;
private String userName;
public String getPhone() {
return phone;
}
public String getPwd(String qweasd) {
return pwd;
}
public String getRePwd(String qweasd) {
return rePwd;
}
public String getUserName(String zhubajie8) {
return userName;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public void setRePwd(String rePwd) {
this.rePwd = rePwd;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Override
public String toString() {
return "SignUpRequest{" +
"phone='" + phone + '\'' +
", pwd='" + pwd + '\'' +
", rePwd='" + rePwd + '\'' +
", userName='" + userName + '\'' +
'}';
}
}
package com.guoyasoft.aotutest001.javabean.signup;
/**
* @program: aotu-test
* @description:
* @author: Administrator
* @create: 2018-11-21 11:53
**/
public class SignUpResponse {
private String respCode;
private String respDesc;
public String getRespCode() {
return respCode;
}
public String getRespDesc() {
return respDesc;
}
public void setRespCode(String respCode) {
this.respCode = respCode;
}
public void setRespDesc(String respDesc) {
this.respDesc = respDesc;
}
@Override
public String toString() {
return "SignUpResponse{" +
"respCode='" + respCode + '\'' +
", respDesc='" + respDesc + '\'' +
'}';
}
}
package com.guoyasoft.aotutest001.testcase.signuptest;
import static com.alibaba.fastjson.JSON.toJSONString;
import com.alibaba.fastjson.JSON;
import com.guoyasoft.aotutest001.javabean.login.LoginResponse;
import com.guoyasoft.aotutest001.javabean.signup.SignUpRequest;
import com.guoyasoft.aotutest001.javabean.signup.SignUpResponse;
import com.guoyasoft.aotutest001.tools.HttpTools;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* @program: aotu-test
* @description:
* @author: Administrator
* @create: 2018-11-21 11:55
**/
public class SignUpTest {
@Test
public void singnup(){
//1. 根据接口规范编写请求响应javabean
//2. 根据接口规范编写测试类
//3. 实例化请求javabean 进行设值
//4. 根据接口规范对设值后的javabean进行转换格式 调用JSON.toJSONtring()
//5. 根据接口规范声明请求路径
//6. 调用httpTool工具类 调用 dopostjson 方法传入请求接口路径 json数据内容 编码格式
//7. 声明变量保存执行接口请求后响应结果内容
//8. 调用响应javabean保存响应结果使用json转对象方法 JSON.parseObject()
//9. 添加断言,断言响应结果是否正确
SignUpRequest req=new SignUpRequest();
req.setPhone("15221487454");
req.setPwd("qweasd");
req.setRePwd("qweasd");
req.setUserName("zhubajie0");
System.out.println(req);
//转成josn
String reqjson= toJSONString(req,true);
System.out.println("转换成json的格式"+reqjson);
String url="http://qa.guoyasoft.com:8080/user/signup";
String bianma= HttpTools.doPostByJson(reqjson,url,"UTF-8");
SignUpResponse respsjson=JSON.parseObject(bianma,SignUpResponse.class);
System.out.println("打印响应码"+respsjson.getRespCode());
}
}
网友评论