how do i fail a test if postman response status code is 500 server error?

依然范特西╮ 提交于 2020-06-15 22:23:52

问题


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. What can i do?

One of my tests isn't even run it looks like: tests["Status code is 201 Created"] = responseCode.code === 201;

Thanks in advance for your help. Tien.


回答1:


You can check that HTTP code is not 500 with following:

tests["Status code is not 500"] = responseCode.code != 500;

Is this what you're looking for?




回答2:


Error 500 means either you are sending some invalid JSON in your request body or some issue with your server. 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.




回答3:


Your test script probably contains invalid JSON. Validate it using a JSON validator.



来源:https://stackoverflow.com/questions/43357786/how-do-i-fail-a-test-if-postman-response-status-code-is-500-server-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!