Cucumber with Spring Boot 1.4: Dependencies not injected when using @SpringBootTest and @RunWith(SpringRunner.class)

后端 未结 5 1605
情深已故
情深已故 2021-02-07 16:43

I am writing a new app and trying to do BDD using cucumber and Spring Boot 1.4. Working code is as shown below:

@SpringBootApplication
public class Application {         


        
5条回答
  •  伪装坚强ぢ
    2021-02-07 17:01

    I had the same problem. The comment from above directed me to the solution

    The problematic code in cucumber-spring seems to be this github.com/cucumber/cucumber-jvm/blob/master/spring/src/main‌​/…

    After adding the annotation @ContextConfiguration the tests are working as expected.

    So what i've got is the following...

    @RunWith(Cucumber.class)
    @CucumberOptions(plugin = {"json:target/cucumber.json", "pretty"}, features = "src/test/features")
    public class CucumberTest {
    }
    
    @ContextConfiguration
    @SpringBootTest
    public abstract class StepDefs {
    }
    
    public class MyStepDefs extends StepDefs {
    
        @Inject
        Service service;
    
        @Inject
        Repository repository;
    
        [...]
    
    }
    

    I hope this helps you further

提交回复
热议问题