Search code examples
javaspringrestspring-cloud-contract

Should Spring Cloud Contract tests actually call an external service?


I'm having trouble finding out the answer to this..

I'm exposing an endpoint, JSON data is being sent to it.

Inside my service I'm then mapping this to a POJO, serialising to a JSON request, then firing that on to my service via OpenFeign (internal service within company).

Should I be mocking everything in terms of the response? Or are contract tests meant to test this integration?

Currently I am analysing the actual response from the service I'm calling.


Solution

  • On the producer side, your controller should have all the services mocked. It means that it will not call a database nor another service to get back the response. What you should do is to create a simple controller object and inject fake / mocked services that will return fixed responses. Contract tests are about checking if you can communicate, not about checking if the functionality is working fine.