
接口

java
导入 : import
类:方法-变量
方法:声明--权限 无返回值类型 方法名(参数列表){方法体}

权限:public(公有)、 private(私有) 、 protect(安全)
返回值类型:boolean (布尔)、 string (字符串)、int(数字)、 void(无返回值)
方法名-规则(第一个单词首字母大写,后续的字面小写)

使用--方法名(参数):参数:类型、个数、位置

注释

@test 是给机器看的
\注解是给人看的,相当于数据库里面的--+空格一样的作用
@test的方法来自于testNg这个jav包,说明这个方法是要执行的

测接口
public class TestAPI{
@Test
//正常流-全字段正常
public void testAddccountAll(){
//请求url
String url ="http://qa.guoyasoft.com:8080/account/add";
//请求参数
String date ="accountName=siwifgdsfg&customerName=偲偲";
//使用daPost方法给服务器发送请求
String result = HttpClientUtil.doPost(url, "application/x-www-form-urlencoded", date);
System.out.println(result);
boolean actul =result.contains("\"respCode\":\"0000\"");
Assert.assertEquals(actul,true);
}
/*
@Test
//异常流-accountname为空
public void testAddccountERRoR(){
//请求url
String url ="http://qa.guoyasoft.com:8080/account/add";
//请求参数
String date ="accountName&customerName=偲偲";
//使用daPost方法给服务器发送请求
String result = HttpClientUtil.doPost(url, "application/x-www-form-urlencoded", date);
System.out.println(result);
boolean actul =result.contains("\"respCode\":\"9999\"");
Assert.assertEquals(actul,true);
}
@Test
public void testAddccountchaochang(){
//请求url
String url ="http://qa.guoyasoft.com:8080/account/add";
//请求参数
String date ="accountName=siwisjhshsjhkjlkjlkjlkhjkghjnjkhuyhiuy&customerName=偲偲";
//使用daPost方法给服务器发送请求
String result = HttpClientUtil.doPost(url, "application/x-www-form-urlencoded", date);
System.out.println(result);
boolean actul =result.contains("\"respCode\":\"9999\"");
Assert.assertEquals(actul,true);
}
@Test
public void testAddcc(){
//请求url
String url ="http://qa.guoyasoft.com:8080/account/add";
//请求参数
String date ="accountName=%$%^&customerName=偲偲";
//使用daPost方法给服务器发送请求
String result = HttpClientUtil.doPost(url, "application/x-www-form-urlencoded", date);
System.out.println(result);
boolean actul =result.contains("\"respCode\":\"9999\"");
Assert.assertEquals(actul,true);
*/
@Test
public void testGetAccountall33(){
//正常流-查询账户接口_全字段正常
//url
String url = "http://qa.guoyasoft.com:8080/account/get?accountName=sisi";
//发送请求
String result = HttpClientUtil.doGet(url);
//打印响应内容
System.out.println(result);
//判断响应里边是否包含
boolean actual = result.contains("customerName\":\"偲偲");
//断言
Assert.assertEquals(actual,true);
}
@Test
public void testRechargeAll(){
//rul
String url = "http://qa.guoyasoft.com:8080/accountBill/recharge";
//post
String data = "{\n"
+ " \"accountName\": \"sisi\",\n"
+ " \"busiDesc\": \"string\",\n"
+ " \"changeMoney\": 10000,\n"
+ " \"mark\": \"string\",\n"
+ " \"operator\": \"string\"\n"
+ "}";
//使用get方法给服务器发请求
String result = HttpClientUtil.doPost(url,"application/json",data);
//打印响应内容
System .out.println(result);
//是否包含
boolean actual = result.contains("respCode\":\"0000");
//断言
Assert.assertEquals(actual,true);
一个添加账户的页面


配置方法的顺序



网友评论