2016-06-28 21 views
0

我的主應用程序運行在springboot中,並且我實現了一個服務,服務器運行正常,所有unitests都通過了,並且服務正常運行(所有postman請求都成功了,所有測試通過)。試圖移動到黃瓜測試。春黃瓜不注入服務

@Inject 
private servicesImpl serviceImpl; 

總是空,我不明白爲什麼autowired/inject不能實際注入服務。 這些類上的註釋:

@RunWith(Cucumber.class)  
@WebIntegrationTest 
@SpringApplicationConfiguration(classes = UniversityApplication.class) 

這些都是我的黃瓜依賴關係:

compile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.4' 
compile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.4' 

回答

0

創建黃瓜測試類爲:

@RunWith(Cucumber.class) 
@CucumberOptions(features = "src/test/resorces") 
public class CucumberTest { 
} 

和步驟定義類爲:

@ContextConfiguration(classes = TestApplication.class, 
         loader = SpringApplicationContextLoader.class) 
@RunWith(SpringJUnit4ClassRunner.class) 
@TestPropertySource(locations = "classpath:test.properties") 
@WebAppConfiguration 
@IntegrationTest 
public class StepsDefinitions { 

    @Inject 
    Services servicesImpl; 
} 

和彈簧啓動應用程序:

@SpringBootApplication 
public class TestApplication { 

    @Bean 
    Service service() { 
    return new ServiceImpl(); 
    } 
} 
+0

試過了,沒有工作,與@噴射/ @自動裝配服務仍然爲空 – MichaelK

+0

忘了補充@IntegrationTest上StepsDefinitions –

+0

沒有解決我的問題 – MichaelK