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