I'm using Spring, Cucumber and Junit in my project. The test runner is annotated with @ContextConfiguration
so it creates a Spring context before running the suite.
I would like Spring to instantiate the Step Definition classes as Spring beans so I can inject my dependencies and use them in the steps. It can be done by declaring the class as @Component
.
So far so good. The problem is that Cucumber will instantiate the step definitions again and will not use the beans already created by Spring with the dependencies injected.
Any ideas to make Cucumber use the Step definitions instantiated by Spring?