Skip to content

Instantly share code, notes, and snippets.

@abhilashshettigartrt
Last active March 27, 2019 12:10
Show Gist options
  • Save abhilashshettigartrt/27666a2323f1ba934aea2e8cf160b6f6 to your computer and use it in GitHub Desktop.
Save abhilashshettigartrt/27666a2323f1ba934aea2e8cf160b6f6 to your computer and use it in GitHub Desktop.
Postman Test cases
// example using pm.response.to.have
pm.test("response is ok", function () {
pm.response.to.have.status(200);
});
// example using response assertions
pm.test("response should be okay to process", function () {
pm.response.to.not.be.error;
pm.response.to.have.jsonBody("");
pm.response.to.not.have.jsonBody("error");
});
// example using pm.response.to.be*
pm.test("response must be valid and have a body", function () {
// assert that the status code is 200
pm.response.to.be.ok; // info, success, redirection, clientError, serverError, are other variants
// assert that the response has a valid JSON body
pm.response.to.be.withBody;
pm.response.to.be.json; // this assertion also checks if a body exists, so the above check is not needed
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment