@
@
@Twitt2019-11-29 18:06:00
API
@Twitt, 2019-11-29 18:06:00

Do I understand the essence of Tests in Postman correctly?

They asked me to write a couple of tests in postman. I didn’t even know that such a thing exists, but here are some of the examples that are in the postman template itself.
For example:

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

My endpoint can respond with 200, 400 and 500 responses. The test above requires that the answer is always 200. Do I understand correctly that in an ideal world, I should write tests that answer as 200? For example, I make myself a test in which I check that the answer has one argument. Of course, if there is a 400 response, then this argument will not be, and the test will automatically fail.
The essence of the question: I should write tests only for the http response 200 OK, and not cover the tests for responses !== 200? I hope I explained my thoughts clearly)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vitsliputsli, 2019-11-29
@Vitsliputsli

It doesn't matter where you write the tests. A test is an emulation of a certain situation and a comparison of the result obtained with the expected one. It doesn't matter if it's 200 or 400. You're sending a valid request and expecting to get 200 in response, if you get it, it's ok. You send a request with erroneous data and expect a 400 response, you received something else, which means fail. Because this is also incorrect behavior.
Another thing is that it is better to first cover standard behavior with tests, and not only return codes, but also data, and then exceptions, errors, and so on.

K
Kirill Gorelov, 2019-11-29
@Kirill-Gorelov

https://learning.getpostman.com/docs/postman/script...

D
Dimonchik, 2019-11-30
@dimonchik2013

wrong
, there is a very simple and clear rule:
the code must RETURN the result where it IS NECESSARY,
and
DO NOT RETURN where it IS NOT NECESSARY
, but with the second half, progers just have trouble when it becomes a habit - consider it, COMPREHENSIVE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question