如何测试服务器返回401 [英] How to test that server returns 401
问题描述
我想创建一个jmeter
测试,如果服务器返回401
,则该测试应该通过.我还想测试邮件正文是否包含json
.
I want to create a jmeter
test which should pass if the server returns 401
. I also want to test that the message body contains a json
.
到目前为止,我已经做到了
I have done this so far
但是测试用例失败了.为什么?
But the test case is failing. Why?
更新
我以为我应该在response assertion
中使用ignore status
,但是如果json
主体不匹配,则测试颜色会同时变为绿色和红色.我很困惑正在发生的事情以及测试是否通过.
UPDATE
I thought I should use ignore status
in response assertion
but then the test color comes up as both green and red if the json
body doesn't match. I am confused what is happening and whether the test has passed or not.
推荐答案
看来我做错了几件事.
- 首先,断言应该是请求的子代.
- 响应断言应将响应代码检查为
401
,但也应检查ignore status
,否则jmeter
会将消息解释为错误
- First, the assertions should have been children of the request.
- The response assertion should check response code as
401
butignore status
should also be checked otherwisejmeter
interprets the message as error
"忽略状态:选中此复选框将通知JMeter不要将返回其认为错误的响应代码的页面标记为错误(任何与2XX,3XX不同的内容).当您知道某个请求应该以某种方式失败并且想要检查它是否确实如此时,这将非常有用.
"Ignore Status : Checking this checkbox tells JMeter to not mark in error a page that returns a response code that it considers in error (Anything different from 2XX, 3XX). This is useful when you know a request should fail in a certain way and you want to check it does"
这篇关于如何测试服务器返回401的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!