I just started to adopt Pact test for my system that consists of one provider service and an Angular frontend as the consumer. I succeeded in setting up both sides, thus, the Angular application generates a (single) pact file with many interactions to multiple endpoints of my provider service. In the provider, I do now face the issue that my verification test gets very large and overly complicated since I have to mock all my endpoints in a single test with all their data, e.g.:
@Provider("example-backend")
@PactFolder("pacts")
@SpringBootTest(...)
class ComprehensivePactTest {
[...]
@State("healthy")
fun `healthy state`() {
whenever(exampleService.dosomething(any())).thenReturn(exampleResponse)
whenever(otherService.somethingElse()).thenReturn(otherResponse)
}
}
Is there a way to seperate the interaction from the pact file such that I could have multiple small verification tests in my provider? For instance, I would like to have a verification test for all requests with path starting with "/example" and a second test for path starting with "/other".
So what I would prefer to have is smaller, focused verification test like so:
@Provider("example-backend")
@PactFolder("pacts")
@SpringBootTest(...)
class ExampleEndpointPactTest {
[... include some filter logic here ...]
@State("healthy")
fun `healthy state`() {
whenever(exampleService.dosomething(any())).thenReturn(exampleResponse)
}
}
@Provider("example-backend")
@PactFolder("pacts")
@SpringBootTest(...)
class OtherEndpointPactTest {
[... include some filter logic here ...]
@State("healthy")
fun `healthy state`() {
whenever(otherService.somethingElse()).thenReturn(otherResponse)
}
}
Or do I have a fallacy in my thinking? Thanks.