Given the following Spring Cloud setup: A data-service
with access to a database, an eureka-service
to handle service registry and discovery and a third service business-service
which will be one of various services which encapsulate business cases.
Unit testing the data-service
is no problem, I just turn off eureka via
eureka.client.enabled=false
and use an in-memory database for my tests.
To access the data-service
from business-service
, I'm using an @FeignClient("data-service")
annotated interface named DataClient
which is @Autowired
where needed. The service is discovered by Eureka, if both are running. This works fine for a production-like setup with all services running.
But now I want to unit test some features of my business-service
. It wouldn't be a problem to start a test service with
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
@SpringApplicationConfiguration(classes = Application.class)
like I'm doing in data-service
. The problem is the Eureka-dependent discovery of my FeignClient
... So my testclass crashes, because the autowiring my DataClient
-instance doesn't work.
Am I abled to tell Spring to use a faked instance of DataClient
just for my tests? Or is the only way to get my tests running an accessible, running instance of data-service
and my Eureka server?