I have in mind to use Postman as a contract testing suite. I’ve run into a scenario and I’m not sure what the idiomatic Postman-y way of solving it might be.
Suppose I have a sequence of requests something like:
- POST to /someResource should return a 2XX
- POST to /someResource a second time should return a 4XX
In essence I want to make the same request twice but the response should fail after the first success. This would be to enforce a business rule like “only one member of this resource can be created”.
The challenge is I’m not sure how to implement the tests. At the moment I’m thinking of a couple options:
- The simplest would just be to duplicate the request body with a different test script. I don’t love the duplication of logic this would encourage
- Another option might be to somehow parameterize the test assertions and use
setNextRequest
to iterate through different scenarios. Intuitively this feels a bit klugey so I wanted to check in with community to see if I’m missing a clearly better option.
Would one of these be an expected approach? Is there a third option I’m not aware of?
Thanks!