Sunday, December 28, 2014

Apache JMeter - Testing RESTful WebServices

In this Tutorial let us see how to use Apache's JMeter to test the RESTful WebServices we developed in my previous post RESTful-web-service-with-spring-3x

1. Download JMeter Click here to download
2. This version requires Java 6 or later
3. Create a Thread Group and give a name, e.g "RestServiceTestingGroup"

4. Set "Number of Threads (Users)" to 5
5. Set "Ramp-up period (in seconds) to 1
6. Set "Loop Count" to 2

7. Right Click on RestServiceTestingGroup and choose Add->Sampler->HTTP Request

8. Give "getStockInformation" as Name
9. Set "localhost" in the "Server Name or IP" field
10. Give 8080 as "Port Number" value
11. Set "http" as Protocol
12. Choose "Post" as Method
13. Type "stock-service-war/stockService/getStockInformation" in the "Path" field
14. Open the "Body Data" Tab and paste the following XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><stockRequest xmlns="http://com.mycompany.model.demo/stockRequest" xmlns:ns2="http://com.mycompany.model.demo/stockResponse"><stockSymbol>AAPL</stockSymbol><stockSymbol>GOOG</stockSymbol><stockSymbol>IBM</stockSymbol></stockRequest>

15. Right Click on RestServiceTestingGroup and choose Add->Listener->View Results Tree

16. Type "stockInfoServiceResult" in the Name field
17. Right Click on RestServiceTestingGroup and choose Add->Config Element->HTTP Header Manager

18. Leave the Name field as it's, if you want you can give a name
19. Clikc on "Add" button at the bottom
20. Type "Content-Type" in the "Name" field and "application/xml" in the Value field
21. Right Click on RestServiceTestingGroup and choose Add->Listener->View Results in Table

22. Now Click on "Start" button

23. To see the Request/Response Click on the "stockInfoServiceResult" on the Left navigation, click on the "getStockInformation" on the Right side panel and open "Request" & "Response" Tabs on the Right side

24. To see Timing statistics click on the "View Results in Table" on the Left navigation bar, this View shows How many times the service is invoked, What is the time taken for each service call, What is the average time of service call etc..
  
25. To get the JSON response from the Service choose "HTTP Header Manager" on the Left panel, Click the "Add" button on the bottom right side, Type "accept", "applicatoin/json" respectively in the Name and Value fields
26. Now hit the "Start" button, you can clear the existing results by clicking on "Clear" & "Clear All" buttons on the Tool Bar. The "stockInfoServiceResult" shows the JSON Response




No comments:

Post a Comment