Hi all, I am quite new to PACT and contract based...
# general
b
Hi all, I am quite new to PACT and contract based testing. And i was wondering, do you have or need assertions in the unit tests that generate the PACTs? What is your view on this? Tnx
y
hey, Pact the framework, generates pact files. ( note none are all uppercased ) and yes, without assertions what are you testing on the consumer side? that you can call your provider. you wouldn’t be checking your code actually does something with that response. also the target of those assertions isn’t to test the provider but to test the consumer in known scenarios
b
Hi Yousaf, Thank you for your reply. just to verify, checking if the consumer can work with the response could also be handled in other tests right? or is it best practice that you enhance the existing unit tests with the creation of the Pact?
no problem 1
y
I would replace your mocked provider with pact, in your existing unit tests, otherwise it sounds like a duplication of effort
m
The way I think about it, is to start with the goal of writing a good set of unit tests for your API client. An important side-effect of doing this with Pact is that you also produce an API contract you can use for contract testing. I said this so many times, I put it as the golden rule here: https://docs.pact.io/consumer I think once you think about contract tests in this way, many other questions fall into place (e.g. which layer to stub)
💯 1
So the answer would probably be “yes”. You should have assertions, just don’t assert that the API client got the data back (because Pact will do this). Assert on the behaviour of your API client
b
Thanks for the replies 🙏
👍 1