如何测试服务器返回401 [英] How to test that server returns 401

查看:96
本文介绍了如何测试服务器返回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.

推荐答案

看来我做错了几件事.

  1. 首先,断言应该是请求的子代.
  2. 响应断言应将响应代码检查为401,但也应检查ignore status,否则jmeter会将消息解释为错误
  1. First, the assertions should have been children of the request.
  2. The response assertion should check response code as 401 but ignore status should also be checked otherwise jmeter 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆