Given the following Spring cloud setup: A data-servicewith database access, eureka-servicefor registry processing and service discovery, and a third service business-service, which will be one of the various services that encapsulate business cases.
Testing the device is data-servicenot a problem, I just turn off eureka through
eureka.client.enabled=false
and use the in-memory database for my tests.
To access data-servicefrom business-service, I use @FeignClient("data-service")an annotated interface with the name DataClient, which if necessary @Autowired. The service is open to Eureka if both work. This is great for a production installation with all services running.
But now I want to unit test some functions of mine business-service. It would be nice to run a test service with
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
@SpringApplicationConfiguration(classes = Application.class)
how am i doing in data-service. The problem is opening Eureka-dependent mine FeignClient... So my test class crashes because auto-installation of my DataClient-instance does not work.
How can I tell Spring to use a fake instance DataClientonly for my tests? Or is this the only way to get my tests to run an available, running instance data-serviceand my Eureka server?
source
share