There's more...

By using the newman package (install it with npm install newman --save-dev), you can run your Postman tests from the command line, which could also allow you to include them in a continuous integration workflow. First, export your collection from Postman (uninspiredly, I called mine postman_collection.json), and then add a new script to your package.json file called "newman":"newman run postman_collection.json". Using npm run newman will then produce an output like the one shown in the following code snippet. You could also test whether all of the tests ran satisfactorily or whether there was a problem:

> npm run newman

> [email protected] newman /home/fkereki/MODERNJS/chapter05
> newman run postman_collection.json

newman

Restful server testing for regions

Test Delete
↳ Get JWT
POST localhost:8443/gettoken [200 OK, 386B, 14ms]
✓ Response is long enough
✓ Response has three parts

↳ Delete non-existing region
DELETE localhost:8443/regions/zz/99 [404 Not Found, 255B, 4ms]
✓ Status code is 404 baby!!

Test Get
↳ Get JWT
POST localhost:8443/gettoken [200 OK, 386B, 2ms]
✓ Response is long enough
✓ Response has three parts

↳ Get /regions/uy
GET localhost:8443/regions/uy [200 OK, 1.46KB, 2ms]
✓ Answer should be JSON
✓ Answer should have at least 19 regions

↳ Get /regions/uy/10
GET localhost:8443/regions/uy/11 [200 OK, 303B, 2ms]
✓ Answer has a single region
✓ Country code is UY
✓ Region code is 11
✓ Region name is Paysandu
✓ Answer is valid, JSON


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset