We will focus on functional testing REST APIs with JSON responses, since this is a common practice in most applications. Nowadays, most developers prefer to use REST API to access web services. This can be used, for example, to pass data from backend services to mobile devices. We will then parse the response with a JSON extractor.

5a1c176562a92.jpg

  1. First, make sure you have JMeter installed on your computer.

  2. After JMeter is installed and opened, you should see an empty test plan:

Increase imageapi testing, jmeter, json extractor

  1. Add the Thread Group:
    Right click on the name of your test plan
    Select ‘Add’
    Threads (Users)
    Thread Group

  2. Add the HTTP request sampler:
    Right click on Thread Group (This way the sampler will be added to this Thread Group)
    Sampler
    HTTP Request

Increase imagejmeter json extractor api testing

  1. Click on this HTTP Request on the left panel and fill in the requested data. Increase imageapi testing json responses

This is all we need to create the GET request.

  1. Now we need to parse the JSON response, so we can verify the values we got. Let’s add the JSON Extractor for this purpose. Right click on HTTP Request Post Processors JSON extractor

Increase imagejson api testing jmeter

  1. The JSON extractor requires us to follow a few steps so we can process the JSON correctly

  2. Now we will add a JSR223 Assertion:
    Right click on HTTP Request
    Assertions
    JSR223 Assertion

By using this assertion, we can Assert the values that we extracted from the JSON response

  1. Make sure the language is Groovy

  2. We used id to fail the test. We can see the test is failing in the View Results Tree listener:
    Right click on HTTP Request
    Listener
    View Results Tree

  3. Run the test. You will see the test has failed and you will see the message we added in our Groovy script:

Increase imageapi testing json response

Now let’s fix the test.

  1. Change jsonString

  2. Run the test again:

Increase imageapi functional testing jmeter

The test passed!

Now that we have the full test, we can expand it to a test plan, and use it for load testing. As you can see, JMeter is a great tool for functional API testing as well, and it enables use to stay in the same JMeter environment.

We will focus on functional testing REST APIs with JSON responses, since this is a common practice in most applications. Nowadays, most developers prefer to use REST API to access web services. This can be used, for example, to pass data from backend services to mobile devices. We will then parse the response with a JSON extractor. ![5a1c176562a92.jpg](serve/attachment&path=5a1c176562a92.jpg) 1. First, make sure you have JMeter installed on your computer. 2. After JMeter is installed and opened, you should see an empty test plan: Increase imageapi testing, jmeter, json extractor 3. Add the Thread Group: Right click on the name of your test plan Select ‘Add’ Threads (Users) Thread Group 4. Add the HTTP request sampler: Right click on Thread Group (This way the sampler will be added to this Thread Group) Sampler HTTP Request Increase imagejmeter json extractor api testing 5. Click on this HTTP Request on the left panel and fill in the requested data. Increase imageapi testing json responses This is all we need to create the GET request. 6. Now we need to parse the JSON response, so we can verify the values we got. Let’s add the JSON Extractor for this purpose. Right click on HTTP Request Post Processors JSON extractor Increase imagejson api testing jmeter 7. The JSON extractor requires us to follow a few steps so we can process the JSON correctly 8. Now we will add a JSR223 Assertion: Right click on HTTP Request Assertions JSR223 Assertion By using this assertion, we can Assert the values that we extracted from the JSON response 9. Make sure the language is Groovy 10. We used id to fail the test. We can see the test is failing in the View Results Tree listener: Right click on HTTP Request Listener View Results Tree 11. Run the test. You will see the test has failed and you will see the message we added in our Groovy script: Increase imageapi testing json response Now let’s fix the test. 12. Change jsonString 13. Run the test again: Increase imageapi functional testing jmeter The test passed! Now that we have the full test, we can expand it to a test plan, and use it for load testing. As you can see, JMeter is a great tool for functional API testing as well, and it enables use to stay in the same JMeter environment.
edited Nov 27 '17 at 7:17 pm
 
0
reply
62
views
0
replies
1
followers
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft