简体   繁体   English

POSTMAN-即使对于错误的测试数据,也会通过架构验证

[英]POSTMAN - Schema validation is passed even for incorrect test data

tests["validating schema "] = tv4.validate(testdata, schema) is passed even if "code" and "status" missing in test data. 即使在测试数据中缺少“代码”和“状态”,也将通过tests [“ validating schema”] = tv4.validate(testdata,schema)。 How to make sure that response and test data schema both are matching for JSON schema. 如何确保响应和测试数据模式都与JSON模式匹配。

  var testdata={
"csosProfileDataList": [
{
  "profileName": "cameron test",
  "deaRegisteredName": "COLISEUM SAME DAY SURG CTR#712",
  "deaLicenseNo": "BP6117004",
},
{
  "profileName": "Vaseem!@#$%%",
  "code": 69022,
  "deaRegisteredName": "COLISEUM SAME DAY SURG CTR#712",
  "deaLicenseNo": "BP6117004",
  "status": "COMPLETE"
}
]
};

 var schema={
"type":"object",
"properties":{
"csosProfileData":{
    "type":"array",
    "items":{
        "type":"object", 
    "properties":{
    "profileName":{"type":"string"},
    "code":{"type":"string"},
    "deaRegistrationName":{"type":"string"},
    "deaLicenseNo":{"type":"string"},
    "status":{"type":"string"}
},
 "required":["profileName", "code", "deaRegistrationName", "deaLicenseNo", "status"]
    }

}
}

};
tests["validating schema "] = tv4.validate(testdata, schema);

Your schema has a couple spelling mistakes in it which is why it is not validating correctly. 您的架构中存在一些拼写错误,这就是为什么它无法正确验证的原因。 Due to the misspelling, the validator was not using the item information to validate and was only validating that the root was an object. 由于拼写错误,验证器未使用项目信息进行验证,而仅验证根是对象。 I've included an updated schema. 我包括了一个更新的架构。

let schema = {
"type":"object",
"required" : ["csosProfileDataList"],
"properties":{
    "csosProfileDataList":{
        "type":"array", 
        "items" : [{
            "type":"object",
            "required":["profileName", "code", "deaRegisteredName", "deaLicenseNo", "status"],
            "properties":{
                "profileName":{"type":"string"},
                "code":{"type":"string"},
                "deaRegisteredName":{"type":"string"},
                "deaLicenseNo":{"type":"string"},
                "status":{"type":"string"}
            }
        }]
    }
}};

When testing I usually add some logging after my test so I can see where it might be failing 在测试时,我通常会在测试后添加一些日志记录,以便可以查看失败的地方

console.log(JSON.stringify(tv4)); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM