Quick question if it's possible to define multiple classes on provider side to test different interactions per endpoint. Let's say provider exposes an API with 2 endpoints:/api/v1/users
and /api/v1/friends
.
Let's also assume we have two consumer services each defining a pact contract. Consumer A
is using both provider APIs and consumer B
only needs /api/v1/users/:id
. Question is how to define a provider test for each endpoint separately?
Running tests in a single test means we need to define mocks for all service
/clients
/repository
/etc. classes per each @State
used from both endpoints - which gets really messy and hard to maintain.
One solution or better say workaround I've found is to use @State
value as a target endpoint and parameters to carry all the rest. But curious to know if I'm missing anything from documentation or if there is a best practices for that.
Same problem arises when we define multiple API versions, i.e. if we introduce /api/v2/users
.
Alternative option would be to call a provider not after microservice but after each endpoint of that microservice. So instead of having two pairs consumerFoo -> providerFoo
and consumerBar -> providerFoo
we gonna have three pairs consumerFoo -> providerFoo.users
,consumerBar -> providerFoo.users
,consumerBar -> providerFoo.friends
. That improves granularity level of a dependency matrix but might as well add some confusion to it.