5

मैं यह पता लगाने की कोशिश कर रहा हूं कि यूरेका का उपयोग करने वाले स्प्रिंग बूट एप्लिकेशन पर एकीकरण परीक्षण कैसे बनाया जाए।यूरेका सेवाओं का उपयोग कर एकीकरण परीक्षण स्प्रिंग बूट सेवा

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 यूरेका है कि मुझे डिस्कवरी क्लाइंट के परीक्षण के लिए निर्माण करने के लिए कॉन्फ़िगर करने की आवश्यकता है?

+2

वहाँ एक कारण है कि आप नहीं/'के साथ अपने परीक्षण चलाने के लिए नहीं करना चाहते हैं कर सकते हैं @ IntegrationTest' की तरह [यहां] (https://github.com/spring-cloud-samples/eureka/blob/master/src/test/java/eurekademo/ApplicationTests.java)? –

+0

हाँ .. आप सही हैं। मैं '@ IntegrationTest' या' @ WebIntegrationTest' का उपयोग कर सकता हूं। इन सभी नई टिप्पणियों के साथ बने रहें! पूरी तरह से समस्या हल करता है। मैं दूसरों के लिए कोड का उत्तर दूंगा और संशोधित करूंगा। – RubesMN

उत्तर

6

@ डोनोवैन के लिए धन्यवाद जिन्होंने टिप्पणियों में उत्तर दिया। org.springframework.boot.test पैकेज में फिलिप वेब और डेव सीयर द्वारा निर्मित एनोटेशन हैं जिन्हें मैं अनजान था। बदले गए कोड के साथ एक उत्तर प्रदान करना चाहता था। करने के लिए वर्ग एनोटेशन बदलें:

@WebAppConfiguration 
@RunWith(SpringJUnit4ClassRunner.class) 
@SpringApplicationConfiguration(classes = {Application.class}) 
@IntegrationTest 

या आप वसंत बूट 1.2.1 और प्रयोग कर रहे हैं अधिक से अधिक

@WebIntegrationTest 
@RunWith(SpringJUnit4ClassRunner.class) 
@SpringApplicationConfiguration(classes = {Application.class}) 
+1

यह स्टार्टअप हल करता है, लेकिन आप इस फ़ेक्ड यूरेका क्लाइंट में आसपास के सिस्टम के यूआरएल कैसे प्रदान करते हैं? –

संबंधित मुद्दे