Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assert returned status code HTTP 400 as a success

Tags:

jmeter

I have been using JMeter for a while and only for load tests. I was wondering if I can use it for ordinary functionality testing.

For example: I have a malformed XML and an application returns 400 Bad Request which I expect to be returned - so it's correct but JMeter resolves it as a failure.

I tried Response Assertions but it didn't work...

Is this possible with JMeter?

like image 263
user219882 Avatar asked Apr 13 '12 17:04

user219882


People also ask

How do I get my HTTP status code 400?

Additionally, HTTP status 400 bad request error can happen when the web browser sends cookie data that's too large. In this case, the error message appears as 400 Bad Request – Request Header Or Cookie Too Large. Try clearing your browser cache and cookies to solve this problem.

What is HTTP response code 400?

The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (for example, malformed request syntax, invalid request message framing, or deceptive request routing).

How does JMeter handle response code 400?

As per 400 Bad Request description: So most probably you're sending malformed requests which server doesn't understand. As soon as you amend your JMeter test plan to 100% match requests which are being sent by the real browser it should start working. Don't forget about Cookies and Headers.

When can I return a Bad Request?

A 400 Bad Request, also known as a 400 error or HTTP error 400, is perceived by the server as a generic client error and it is returned when the server determines the error doesn't fall in any of the other status code categories.


1 Answers

To test a non 200 response code, you must check the 'Ignore Status' field in the Response Assertion. Without this, the test will always fail regardless of the response assertion.

So here is what you need to do to test the http response code 400:

Add a new Response Assertion. Set the following assertion properties:

  • check the 'Response Code' radio button.
  • check the 'Ignore Status' box.
  • check the 'Equals' radio button in the Pattern Matching Rules.
  • click the 'Add' button.
  • enter '400' in the row in Patterns to Test.

Done.

like image 102
toconn Avatar answered Oct 09 '22 16:10

toconn