https://github.com/alexndrmac/postman_asserts
Tiny scripts for Postman Auto tests (reusable Assertions for postman tests and json schema validation)
https://github.com/alexndrmac/postman_asserts
autotesting json postman tv4
Last synced: about 2 months ago
JSON representation
Tiny scripts for Postman Auto tests (reusable Assertions for postman tests and json schema validation)
- Host: GitHub
- URL: https://github.com/alexndrmac/postman_asserts
- Owner: AlexNDRmac
- License: gpl-3.0
- Created: 2019-05-08T14:47:19.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-12-16T20:09:33.000Z (3 months ago)
- Last Synced: 2025-12-20T10:58:48.008Z (3 months ago)
- Topics: autotesting, json, postman, tv4
- Language: JavaScript
- Size: 392 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Postman Asserts | provide a clean way to organize tests
[![Build status][actions build badge]][actions build link]
[![Repository certification][codacy badge]][codacy link]
If you want use Tests inside Postman, you must always write assertions like this:
```javascript
pm.test('Response should have JSON Body', function () {
pm.response.to.have.jsonBody();
});
// or
tests["Response Data is Valid"] = tv4.validate(pm.response.json(), schema);
```
It will be better if we can use `Reusable functions` inside Postman. It's more flexible...
## Writing tests within Postman Reusable functions
To have Assertions inside your Collection, you need to do next steps:
- Save content of `pm_asserts.min.js` script as a global variable
- In the Postman `Test scripts` - eval `postman_asserts` global variable
- Call Asserts functions by functions' name
### Setting up Assertions Script to Postman Globals
To set up Assertions - just download [Collection](./PostmanAssertsInit.postman_collection.json) and make API call with it. This Request will get Script content and set up Global variable into Postman Environment.
### Using Assertions inside Postman Tests
Into `Tests` window call Assertions after `eval()` Postman Globals variable, which contains Script body.
```javascript
eval(globals.postman_asserts);
const schema = {
"type": "object",
"required": ['args', 'headers']
};
isJsonResponse();
isResponseStatus(200);
validateJsonSchema(schema);
```
## License
This project is open source software licensed under the GNU General Public License version 3.
[actions build badge]: https://github.com/AlexNDRmac/postman_asserts/workflows/Postman%20Tests/badge.svg "Build status"
[actions build link]: https://github.com/AlexNDRmac/postman_asserts/actions
[codacy badge]: https://api.codacy.com/project/badge/Grade/5cb97130b06542b08ce4a370e9f10679 "Repository certification"
[codacy link]: https://www.codacy.com/manual/AlexNDRmac/postman_asserts