Looking for a working example of Pact contract tes...
# pact-jvm
k
Looking for a working example of Pact contract tests with Feign Client (consumer side) Hi everyone! 👋 I’m currently working on setting up Pact contract tests for a consumer using Feign Client and was wondering if anyone has a recent, working example to share. I’ve found a few examples online, but many seem outdated or don’t quite match our setup. If you’ve implemented this recently or know of a good reference, I’d really appreciate any pointers! Thanks in advance! 🙏
j
HI Katrin, As a feign user and wannabe pact user, I'm wondering why you'd need pacts in this case ? With Feign the provider exposes an API to the consumer and a client implementing this API is created at runtime. So the contract is enforced and cannot be broken on either sides, in my understanding. Am I missing something important here ?
k
Feign gives you a convenient, declarative client based on an expected contract. Pact ensures both sides actually agree on that contract and alerts you when they don’t — which is critical in evolving microservice systems. When you define a Feign client, you’re essentially saying “I expect the provider to have an endpoint that behaves like this.” But Feign doesn’t verify that the provider actually does.
finally found an answer to my question:
Copy code
YourFeignServiceClient youFeignServiceClient = Feign.builder()
                .contract(new SpringMvcContract()) // Register Spring MVC annotations
                .decoder(new ResponseEntityDecoder(new JacksonDecoder())) // Decode JSON to ResponseEntity
                .target(YourFeignServiceClient.class, pactServerUrl); // Target the mock server URL