2018-10-12代码测试接口

代码测接口.png

接口

image.png

java

导入 : import

类:方法-变量

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

image.png

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


image.png

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

image.png

注释

image.png

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


image.png

测接口

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);

一个添加账户的页面

添加账户

image.png

配置方法的顺序

首先复制

删东西

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1 A喜欢写作,也在各大自媒体平台注册了账号,但一开始写就有了一个担忧:怕被盗。 ——因为原创标识是平台邀请制的,...
    悟恩说事阅读 804评论 1 4
  • 对于所有人生,生活的解释,如果抛开它,无限的可能性不谈,那我觉得就没有任何意义。
    LIVDYING阅读 110评论 0 0
  • 上午,早操。 神烦。 有时候总是在想,为什么一切都要那么复杂呢? 早操的时候,园长说,要做17年的年计...
    陌安浅浅阅读 194评论 0 0
  • 如果不能见你,我会每天唱歌给自己 如果能每天见你,每一首情歌都是给你 我拥有许多的鲜花 但没有你的掌声 你存在每一...
    要多帅气的昵称呢阅读 119评论 0 0
  • 朋友圈里总是有一些姑凉,她们总是在尝试新的事物,不管这些有没有意义,她们总是在学习新的技能,不管这些有没有用,...
    兰妮妮只是笑的有点傻阅读 541评论 0 4

友情链接更多精彩内容