Paul Caplan
07/05/2023, 10:48 PMapi_client.upon_receiving('api 1')...
) to a “shared context” (rspec ruby thing) and that shared context in the contract test. Then, in the integration test for the UI, we include the contract for both API calls, something like:
include_context 'api_1'
include_context 'api_2'
It seems to achieve the same exact result with a slightly different way of implementing. It’s not going to automagically find all the correct matching contracts to use; on the other hand it is more explicit in terms of being able to inspect which contracts are actually being stubbed out by Pact for a given test.
Any concerns with this latter approach? It seems that the key to maintainability with either approach, again, is to minimize the number of contracts for a given single API.Timothy Jones
07/06/2023, 12:28 AMTimothy Jones
07/06/2023, 12:28 AMTimothy Jones
07/06/2023, 12:29 AMTimothy Jones
07/06/2023, 12:30 AMIntegration test for UI. Code is calling both API 1 and API 2, both calls hit back stub server, it downloads all the pacts and it matches them to the request and returns appropriate JSON response.I think this is probably just as much maintenance effort as the first-class contract test approach
Timothy Jones
07/06/2023, 12:35 AMIt seems to achieve the same exact result with a slightly different way of implementing.Yes, I agree. I think you'll risk frustrating test maintenance with either approach.
Matt (pactflow.io / pact-js / pact-go)
e.g. if we have 10 different tests that are calling same API, we would have 10 different versions of the contract for the same API (= bad)Yes, this is one of the key problems (and thanks for reading the guidance in advance 🙏 ). If you can avoid that, half of the maintenance problems go away. In my experience, most of the pain with UI tests is pushed to the API provider. So anything you can do to improve situation that is likely to make it more workable.
Matt (pactflow.io / pact-js / pact-go)
Paul Caplan
07/06/2023, 1:35 PM