[英]how do i fail a test if postman response status code is 500 server error?
I'm trying to set up a test where I make a POST request but getting a 500 Server Error (Response Body that I'm seeing is Unexpected 'T' [JSON]; Tests reporting "There was an error in evaluating the test script: SyntaxError: Unexpected token T in JSON at position 0") and so Tests should show Failed for all 5 of my tests. 我正在尝试设置一个测试,我发出一个POST请求,但得到500服务器错误(我看到的响应主体是意外'T'[JSON];测试报告“评估测试时出错script:SyntaxError:位于0的JSON中的意外标记T“)因此测试应显示我的所有5个测试都失败。 What can i do?
我能做什么?
One of my tests isn't even run it looks like: tests["Status code is 201 Created"] = responseCode.code === 201; 我的一个测试甚至没有运行它看起来像:tests [“Status code is 201 Created”] = responseCode.code === 201;
Thanks in advance for your help. 在此先感谢您的帮助。 Tien.
田。
You can check that HTTP code is not 500 with following: 您可以通过以下方式检查HTTP代码是否不是500:
tests["Status code is not 500"] = responseCode.code != 500;
Is this what you're looking for? 这是你在找什么?
Error 500 means either you are sending some invalid JSON in your request body or some issue with your server. 错误500表示您在请求正文中发送了一些无效的JSON,或者您的服务器出现了一些问题。 Could tell more by looking at the request and response body.
通过查看请求和响应正文可以告诉更多。
Do you have your test under any if condition? 你是否在任何条件下进行测试? I don't any reason why the test didn't run except if you have any syntax error in test section.
我没有任何理由为什么测试没有运行,除非你在测试部分有任何语法错误。
Your test script probably contains invalid JSON. 您的测试脚本可能包含无效的JSON。 Validate it using a JSON validator.
使用JSON验证器验证它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.