Hey guys, I have a question. In contract testing, ...
# general
k
Hey guys, I have a question. In contract testing, is is possible to use Consumer-Driven-Contract-Testing to test towards a 3rd party API which one does not control (for example a Google Service API)? If so, how would one go about doing this?
y
Hey, You can, but it is not advised https://docs.pact.io/getting_started/what_is_pact_good_for#what-is-it-not-good-for You run the verifier as standalone https://docs.pact.io/implementation_guides/cli#provider-verifier We introduced Bi-Directional as a way of providing static schema based testing and eliminate some of the verification pains, for situations users were using traditional CDCT, or wished to, for a workflow that wasn't quite suited. With BDCT, the key difference is that a Provider uploads its own provider contract advertising its full capability which is statically compared to the expectations in the consumer contract - the consumer contract is never replayed against the provider code base. This creates a much simpler and decoupled workflow. See the trade-offs for more. With CDCT, you need to write and maintain a separate set of (Pact) tests that are responsible for ensuring systems are compatible. The tests on the consumer side produce a consumer contract containing the example scenarios which must be supported for the consumer to work, which are then replayed against an actual running provider in a record and replay style interaction. If the Provider responds correctly, the contract is valid. Provider states are used to setup the test conditions for assertions on the Provider side, see here for the scope
👍 1
k
Thanks!
m
Yeah. I think we did an AMA on this a while ago too (or at least it was a question).
Search AMA in the docs.pact.io website for that
Whilst not a Pact specific feature, we do have a workflow similar to described in Pactflow: https://docs.pactflow.io/docs/bi-directional-contract-testing. Upload OAS as a provider contract (ideally verified to be valid, but in the case of a 3rd party you’ll just have to trust they have tested their API), generate a consumer contract and Pactflow will ensure they stay compatible.