编程语言
首页 > 编程语言> > java-保证空响应主体结构

java-保证空响应主体结构

作者:互联网

我想测试一个查找休息服务,如果我发现我想从数据库中删除,则什么都不做

我这样使用它(其中rs是find的响应)

 JsonPath jsonPath = rs.getBody().jsonPath();
 Object foundName= jsonPath.get("name");

  if (foundName!= null) {

   expect().statusCode(200).when().delete("..." + foundName);

 }

因此,当什么都没找到时,如何检查它的foundName,因为我尝试了foundName!= null或foundName!=“”,但仍然无法正常工作.
因此,请解释一个空的响应主体的结构是什么

解决方法:

基于调试信息,foundName的类型为List,因此解决方案是将foundName强制转换为List并检查其是否为空.

 List foundName = (List)jsonPath.get("name");
 foundName.isEmpty()

标签:rest,rest-assured,json,java
来源: https://codeday.me/bug/20191121/2055346.html