新建一个javabean文件
-
发送和请求
image.png
右击,Generate,get,set,toString
package com.guoyasoft.aotutest001.javabean.signup;
/**
* @program: aotu-test
* @description:
* @author: Administrator
* @create: 2018-11-21 16:32
**/
public class SignupReq {
private String phone;
private String pwd;
private String rePwd;
private String userName;
public String getPhone() {
return phone;
}
public String getPwd() {
return pwd;
}
public String getRePwd() {
return rePwd;
}
public String getUserName() {
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 "SignupReq{" +
"phone='" + phone + '\'' +
", pwd='" + pwd + '\'' +
", rePwd='" + rePwd + '\'' +
", userName='" + userName + '\'' +
'}';
}
}
package com.guoyasoft.aotutest001.javabean.signup;
/**
* @program: aotu-test
* @description:
* @author: Administrator
* @create: 2018-11-21 16:33
**/
public class SignupResp {
private String respCode;
private String respDesc;
public String getRespCode() {
return respCode;
}
public void setRespCode(String respCode) {
this.respCode = respCode;
}
public String getRespDesc() {
return respDesc;
}
public void setRespDesc(String respDesc) {
this.respDesc = respDesc;
}
@Override
public String toString() {
return "LoginResp{" +
"respCode='" + respCode + '\'' +
", respDesc='" + respDesc + '\'' +
'}';
}
}
再建一个tsetng测试类
package com.guoyasoft.aotutest001.testcase;
import static com.alibaba.fastjson.JSON.parseObject;
import static com.guoyasoft.aotutest001.tools.HttpTools.doPostByJson;
import com.alibaba.fastjson.JSON;
import com.guoyasoft.aotutest001.javabean.signup.SignupReq;
import com.guoyasoft.aotutest001.javabean.signup.SignupResp;
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 16:32
**/
public class SignupTest {
@Test
public void signuptest(){
/* 1.根据接口规范编写请求响应javabean
* 2.根据接口规范编写测试类
* 3.实例化请求javabean 进行设置
* 4.根据接口规范对设置后的javabean进行转换格式 调用JSON.toJSONString()
* 5.根据接口规范声明请求路径
* 6.调用HTTPTool工具类 调用dopostjson方法传入请求接口路径 json数据内容 编码格式
* 7.声明变量保存执行接口请求后响应结果内容
* 8.调用想用javabean保存响应结果使用json转对象方法JSON.parseObject()
* 9.添加断言,断言响应结果是否正确*/
SignupReq req=new SignupReq();
req.setPhone("13105505515");
req.setPwd("qwe123");
req.setRePwd("qwe123");
req.setUserName("chendd06");
String reqjson= JSON.toJSONString(req,true);
System.out.println("已转换为json格式"+reqjson);
String url="http://qa.guoyasoft.com:8080/user/signup";
String body= doPostByJson(url,reqjson,"UTF-8");
System.out.println("响应的结果是"+body);
SignupResp respbody= parseObject(body,SignupResp.class);
Assert.assertEquals(respbody.getRespCode(),"0000","预期业务响应码不一致");
}
}
网友评论