मैं यह पता लगाने की कोशिश कर रहा हूं कि यूरेका का उपयोग करने वाले स्प्रिंग बूट एप्लिकेशन पर एकीकरण परीक्षण कैसे बनाया जाए।यूरेका सेवाओं का उपयोग कर एकीकरण परीक्षण स्प्रिंग बूट सेवा
DiscoveryManager.getInstance().getDiscoveryClient().getApplications();
हो जाएगा ताकि एनपीई: मैं एक परीक्षण
@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 {
// test no registered services
this.mockMvc.perform(get("/api/v1/services").accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$").value(jsonArrayWithSize(0)));
}
}
है और मुझे लगता है कि API कॉल के लिए अपने कोड पथ में है कहो। डिस्कवरी क्लाइंट को शून्य के रूप में वापस कर दिया गया है। अगर मैं स्प्रिंग बूट ऐप सीधे शुरू करता हूं और एपीआई का उपयोग करता हूं तो कोड ठीक काम करता है। मेरे पास कहीं भी कोई विशिष्ट प्रोफ़ाइल उपयोग नहीं है। क्या कुछ विशेष wrt यूरेका है कि मुझे डिस्कवरी क्लाइंट के परीक्षण के लिए निर्माण करने के लिए कॉन्फ़िगर करने की आवश्यकता है?
वहाँ एक कारण है कि आप नहीं/'के साथ अपने परीक्षण चलाने के लिए नहीं करना चाहते हैं कर सकते हैं @ IntegrationTest' की तरह [यहां] (https://github.com/spring-cloud-samples/eureka/blob/master/src/test/java/eurekademo/ApplicationTests.java)? –
हाँ .. आप सही हैं। मैं '@ IntegrationTest' या' @ WebIntegrationTest' का उपयोग कर सकता हूं। इन सभी नई टिप्पणियों के साथ बने रहें! पूरी तरह से समस्या हल करता है। मैं दूसरों के लिए कोड का उत्तर दूंगा और संशोधित करूंगा। – RubesMN