I am trying to figure out how to create integration tests in a Spring boot application that uses Eureka. Say I have a test
@WebAppConfiguration @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = {Application.class}) public class MyIntegrationTest { @Autowired protected WebApplicationContext webAppContext; protected MockMvc mockMvc; @Autowired RestTemplate restTemplate; @Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build(); } @Test public void testServicesEdgeCases() throws Exception {
and I have my code for this api call:
DiscoveryManager.getInstance().getDiscoveryClient().getApplications();
It will be NPE. The discoveryClient property is returned as null. The code works fine if I launch the Spring boot application directly and use the API itself. I have no specific use of the profile anywhere. Is there anything special about Eureka that I need to configure in order for the discovery client to be created for testing?
source share