zoukankan      html  css  js  c++  java
  • 传统方式接口测试返回值json验证

    1.返回值

     

    2.验证方式:

    public void check200_N(Object obj, int ret_num)
    throws UnsupportedEncodingException, Exception {
    JSONObject resultJson = JSONObject.fromObject(obj);
    Assertions.assertThat(resultJson.getString("retCode")).isEqualTo("200");
    Assertions.assertThat(resultJson.getString("retDesc"))
    .isEqualTo("操作成功");
    Assertions.assertThat(resultJson.containsKey("ret")).isTrue();
    
    JSONArray jsonArray = resultJson.getJSONArray("ret");
    Assertions.assertThat(jsonArray.size()).isEqualTo(ret_num);
    Iterator<JSONObject> iterator = jsonArray.iterator();
    while (iterator.hasNext()) {
    JSONObject tmp = iterator.next();
    Assertions.assertThat(tmp.getString("id")).isNotEmpty();
    Assertions.assertThat(tmp.getString("title")).isNotEmpty();
    Assertions.assertThat(tmp.getString("digest")).isNotEmpty();
    Assertions.assertThat(tmp.getString("analystName")).isNotEmpty();
    Assertions.assertThat(tmp.getString("url")).isNotEmpty();
    Assertions.assertThat(tmp.getString("sourceCreateTime"))
    .isNotEmpty();
    Assertions.assertThat(tmp.getString("replies")).isNotEmpty();
    Assertions.assertThat("5,6,4,3,2,1,0").contains(
    tmp.getString("type"));
    Assertions.assertThat(tmp.getString("analystImage")).isNotEmpty();
    Assertions.assertThat(tmp.getString("orderWeight")).isNotEmpty();
    String t = tmp.getString("imageList");
    if (t != null && (!t.equals("null") && t.length() > 2)) {
    JSONArray jsonArray2 = tmp.getJSONArray("imageList");
    Iterator<JSONObject> iterator2 = jsonArray2.iterator();
    while (iterator2.hasNext()) {
    JSONObject tmp2 = iterator2.next();
    Assertions.assertThat(tmp2.getString("originWidth"))
    .isNotEmpty();
    Assertions.assertThat(tmp2.getString("originHeight"))
    .isNotEmpty();
    Assertions.assertThat(tmp2.getString("originUrl"))
    .isNotEmpty();
    }
    }
    }
    System.out.println("测试成功");
    }
  • 相关阅读:
    软件工程实践 2017 第二次作业(部分)
    2017 软件工程实践第一次作业-031502627
    struct与class区别联系(转)
    个人作业——软件工程实践总结作业
    个人作业——软件产品案例分析
    个人技术博客(α)
    结对作业2
    软工作业2
    软工作业1
    作业7 学期总结
  • 原文地址:https://www.cnblogs.com/zyh0430/p/11921510.html
Copyright © 2011-2022 走看看