The following codes are example to demostrate API testing, including Load testing.
- Install NodeJS LTS or NodeJS Portable
- Download this project (either clone or by ZIP)
- Start example server (in the directory of the downloaded project)
npm install npm start
For API testing, we are using Postman. The portable version of it can be downloaded here: postman-portable.
- Install Postman or Postman portable
Based on the api-automation-webinar create API tests in Postman for JSON Placeholder.
N | Method | URL | Parameters | Expected |
---|---|---|---|---|
1 | POST |
/posts |
Body: {"title": "Test post", "body": "This is a nice post", "userId": 1} |
Code: 200; Response contains id |
2 | GET |
/posts/{id} |
Path: id is the ID of the previously added post |
Code: 200; Response contains title , body , id and userId or previously added post |
3 | POST |
/posts |
Body: {"id": {id}, "title": "Test post", "body": "This is a nice post", "userId": 1} where id is the ID of the previously added post |
Code: 500 |
For Load testing, we are using NodeJS and the loadtest tool.
- Install loadtest package:
npm install -g loadtest
-
Start simple load test
- on
GET http://localhost:3456/load
- with 10 concurrent users
- with 10 requests per second
- send 500 requests
loadtest http://localhost:3456/load -c 10 --rps 10 -n 500
- on
-
Start other load test
- on
GET http://localhost:3456/huge
- with 10 concurrent users
- with 10 requests per second
- send 500 requests
loadtest http://localhost:3456/huge -c 10 --rps 10 -n 500
- on