2016-06-28 77 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