【问题标题】:How to Validate variable can have a vale either NULL or in String format如何验证变量可以有一个 NULL 或字符串格式的值
【发布时间】:2019-09-09 10:55:31
【问题描述】:

我开始使用空手道进行测试。我需要验证一个 json 响应。 JSON 架构设计:

response{

 id* Integer Not null
 Name* String can be null

}

现在我需要使用以下约束验证 id 和 name, id 应该是整数并且不应该为空。 名称可以是字符串,也可以为空。

我们可以在空手道中使用什么方程式。

提前致谢

def jsonValidate = {name: '#integer',Name: '#present'}

所以如果我在这里使用 Present ,这意味着 Name 可以是 null 或者可以具有任何数据类型的值。但我需要检查名称只能是字符串或空值

【问题讨论】:

    标签: api karate


    【解决方案1】:

    阅读文档,然后试试这个:https://github.com/intuit/karate#optional-fields

    * def jsonValidate = { id: '#number', name: '##string' }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      相关资源
      最近更新 更多