Skip to content

jivanim/cs122b-tests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

cs122b-tests

Postman (newman) test scripts for HWs

We will post

  1. sample tests before HW deadline so you can have a sense of what the tests looks like and write your own tests.

  2. actual grading tests after HW deadline so you can double check.

Description of tests

Postman (newman) is a javascript tool to test RESTful services. You can change the method (GET/POST/DELETE/PUT, etc.), authentication (Bearer Token/OAuth, etc.), Headers, Params(usually for GET), Body (usually for POST) for a certain request.

There are two scripts part you could write: Pre-request Script and Tests

  • Pre-request Script runs before the request is made, you may generate some random value and set to global variables.
  • Tests runs after the request is done, you may make unit tests to assert on the response you get.

To use the tests with Postman

  1. Download and install latest [email protected]

  2. On the rop left corner, click import

  3. Select the test json to be imported. For example, the BasicService.postman_collection.json

  4. On the top right corner, next to Environment, click the Manage Environment button

  5. Add an environment with two keys: host = localhost, port = your service port. You may also use other environment variables.

  6. Then run the collection of your requests. Under Data section, select the data.json files assoicated with each test.

To use the tests with newman

  1. Download [email protected] with npm install -g newman. Get npm if you do not have it.

  2. Run with the following command: newman run <test_json> --global-var 'host=<your_service_host>' --global-var 'port=<your_service_port>' -d <data_file>

    For example: newman run BasicService.postman_collection.json --global-var 'host=localhost' --global-var 'port=8080' -d ./hw1-test-data.json

To add more tests yourself

  1. Add new requests in postman

  2. Define your request API with http://{{host}}:{{port}} + <API_END_POINT>

  3. Select HTTP method

  4. Define Param (for GET) or Body (for POST)

  5. If using Json, select application/json

  6. Define your Pre-request Script and Tests

About

Postman (newman) test scripts for HWs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors