Postman Alternatives for Api Testing
How to Make Validation on RESTful Web Service Performance Test
How to Make Validation on RESTful Web Service Performance Test
Hello,
Representational State Transfer (REST) is an architectural style that pre-defines a set of constraints to be used for creating web services. Web services that use REST architectural style, or RESTful web services, provide interoperability between any system on the internet. Nowadays many development teams are switching to restful APIs to simplify client and server communication. That’s why performance or stress testing of that web service is crucial.
By following this tutorial, you will be able to validate how many concurrent users your application’s server-side component can handle.
Apache JMeter is strong when it comes to assertions. You can assert the response state or directly to the response data. By using those assertions, you will be able to verify the stability of your application under heavy load. There are different options to make a validation.
- Response Assertion
- JSON Assertion
- JSR223 Assertion
Response Assertion
We talked about response assertions in our SOAP service blog post. You can use the same approach as you used in SOAP web service test as there’s no difference between their usage.
You can measure response times, validate response code or response messages.
JSON Assertion
In order to make a good json assertion, you need to know how to use JSONPath. You can use http://jsonpath.com/ to learn JsonPath.
During a performance test, our approach should be not only monitoring the performance of the application but also the integrity of the response data. So using JSON Extractors and JSON Assertions in one test would be a good fit for our need.
Our scenario is to fetch all books records, extract the id and title of a random book. Then we’ll search for this specific book. Finally, we’ll make an assertion to the response with extracted values.
First, we use JSON extractor component of Apache JMeter. It has 4 different fields
- Names of created variable: We need to define variable names for extracted values. We’ll use those value by using ${variableName} format during the test.
- Json Path expression: This must be obvious 🙂
- Match no: in case your Json Expression return multiple values, this field works as an index for your response. In case you want to randomize the selection, you need to use 0 in that field.
- Default Values: In case there’s no data in the response, you might defined default values.
In case you want to extract multiple data in one action you need to separate your expression, variable by using “;”. By that way, you will be able to extract related data.
Then you need to use JSON Assertion component of JMeter. In this component, all you need to do is to give proper JSON expression to find the attribute and the value to compare.
Right now, your script will be able to compare the expected result and mark your test as pass or fail at the end of execution.
JSR223 Assertion
JSR223 support Groovy, Java or Beanshell script. This feature lets you go beyond the out of the box solution that JMeter provides. You can manipulate the response or create custom assertions. That depends on your need and your imagination.
In this example, we extract the response data, extract the id and check if it’s null or empty. In case it validates those condition, it will fire a failure message with a custom failure message.
Groovy scripting is a must to use this feature.
Happy load testing to your RESTful services. Check out Loadium blog to read more relevant content.