Usually, when I’m writing tests, I already have correctly working HTTP endpoints. It means, when I click the “Send” in postman, the response is correct or sometimes almost correct. So I want to commit the current behaviour with tests. So most often I just write assertions for current response.
So my suggestion is next.
Let say, I have some endpoint, GET https://jsonplaceholder.typicode.com/todos/1. When I send it, the server produces the response:
200 Ok
Body:
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
I want to have a button, maybe in the SNIPPETS panel, maybe named “Assertion for current response”, that will generate the next test:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Body is correct", function () {
pm.response.to.be.json;
const response = pm.response.json();
pm.expect(response.userId).to.eql(1);
pm.expect(response.id).to.eql(1);
pm.expect(response.title).to.eql("delectus aut autem");
pm.expect(response.completed).to.eql(false);
});