Hey. I repeatedly have people saying what they rea...
# general
d
Hey. I repeatedly have people saying what they really want is to write isolated functional tests and then feel confident that the mocks they are using are correct. The way many people are solving this is by doing a record/playback approach, where they run their tests in staging on a weekly basis, record the results, and use these as their mocks. But I thought it would be great to say "use Pact to define your mocks, run your functional tests, and then use the Pact mocks to verify your provider." But in the docs you recommend not doing this for reasons I don't fully understand - something about the mocks defining a contract that is too constrictive and which breaks even when the contract has not broken. Can you explain more? I am very tempted to start using Pact as the mocks for functional tests, but not if this is just a non-starter use of Pact. Thanks!
👋 1
m
Great question. The main issue is that Pact is not a general purpose mocking tool, so often times the mocks aren’t extensive enough to be used in functional tests. A good example is boundary testing - you might want to test a UI that accepts a user’s name with many combinations of short, long and unicode characters. From a contract POV, this is not useful additional information to encode and enforce a provider test for, but if you did it, it could make provider verification more cumbersome.
You can absolutely use the pact stubs in these environments (including the hosted stubs that Pactflow offers). However, there are some limitations to be aware of - such as the lack of provider states to differentiate between different response codes / bodies for a given request. e.g. you might have two tests that cover a
GET /users/1234
, one that returns a
200 {…}
and another that returns a
404
. In this case, the stubs won’t be able to differentiate. This can be mitigated by not having overlapping requests, but is worth noting
In the case of BDCT, the situation changes because we don’t replay all the examples against a provider, so you can create more extensive mocks and that doesn’t create any additional burden on the provider. As long as the mocks are compatible with the provider contracts (OAS) you’re good to go. Mock with impunity! 😉
d
Makes sense, thanks!
👍 1