TestNG Framework Eclipe-logall未正确收集Json响应

问题描述

对于以下代码,当我尝试使用public function loop1($ob):array { return array(1,2,3); } 时,json无法正确打印。

方法PUT-http://dummy.restapiexample.com/public/api/v1/update/6112

请求-{“名称”:“罗纳克”,“工资”:“ 123”,“年龄”:“ 26”}

  • 预期响应:

    log().all()
  • Eclipse日志中的实际响应:

      {
          "status": "success","data": {
              "name": "Ronak","salary": "123","age": "26"
          },"message": "Successfully! Record has been updated."
      }
    
  • 我的代码

    JRE-JAVA 1.8 [jdk-AdoptOpenJDK 8.0]

      Response: 200
      Content-Length: 81
      {
          "status": "success",**"data": [
    
          ],** <--- **this value is missing here**
          "message": "Successfully! Record has been updated."
      }
      PASSED: testPUT
    
  • Pom.XML文件值:

    4.0.0

      package restassuredTests;
    
      import java.util.HashMap;
      import org.testng.annotations.BeforeClass;
      import io.restassured.RestAssured;
      import org.testng.annotations.Test;
      import static io.restassured.RestAssured.*;
      import static org.hamcrest.Matchers.*;
    
      public class Demo3_PUT_Request {
    
          public static HashMap map1 = new HashMap();
          int id = 6112;
    
          @BeforeClass
          public void putData() {
    
              map1.put("name","Ronak");
              map1.put("salary","123");
              map1.put("age","26");
    
              RestAssured.baseURI="http://dummy.restapiexample.com/public/api/v1";
              RestAssured.basePath="/update/"+id;
          }
    
          @Test
          public void testPUT() {
    
              given()
                  .contentType("application/json")
                  .body(map1);
    
              when()
                  .put()
    
              .then()
                  .statusCode(200)
              .and()
                  .body(containsstring("success"))
              .and()
                  .body(containsstring("Successfully! Record has been updated."))
                  .log().all();
    
          }
      }
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)