对于#Postman测试,我有一个嵌套的“ if,if,if,else”测试脚本,但是当它不是本来应该存在的条件而其他条件未正确执行时,我得到了某些条件。
当我在测试条件中注释掉某些部分时,它会按需工作。
var jsonData = JSON.parse(responseBody);
if (responseCode.code === 200){
tests["Http status is 200"] = responseCode.code === 200;
try{
tests["ID: "] = jsonData.id === jsonData.id;
tests["Name is: "] = jsonData.name === jsonData.name;
tests["Description is: "]= jsonData.description === jsonData.description;
}
catch(e){}
}
else if (responseCode.code !== 200){
//using invalid token
tests["Http status is 401"] = responseCode.code === 401;
try{
tests["Response Message is: " + jsonData.error] = jsonData.error;
}
catch(e){}
}
else(responseCode.code !== 200){
//record not found
tests["Http status is 404"] = responseCode.code === 404;
try{
tests["Status Code is " + responseStatus.status] = responseStatus.status;
tests["Response Message is: " + jsonData.message] = jsonData.message;
tests["Time is " + jsonData.timestamp] = jsonDat.timestamp;
}catch(e){}
}