Spring dependencies not introduced for the cucumber runner

I have existing test cases that use SpringJUnit4ClassRunner that use the @Resource annotation to indicate a variable for injection.

@Resource is used because a different DI structure may be used in the future. ( @Resource vs @Autowired )

Now I started writing BDD test cases using the Cucumber runner. However, DI does not seem to be happening. (@ Works, but not @Resource) Does anyone know why not?

+3
source share
1 answer

(I assume you are using Cucumber-JVM)

SpringJUnit4ClassRunner .

@RunWith(Cucumber.class)

, :

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${info.cukes.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${info.cukes.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-spring</artifactId>
        <version>${info.cukes.version}</version>
        <scope>test</scope>
    </dependency>

cucumber.xml . XML XML- spring bean. :

<context:component-scan base-package="cucumber.runtime.java.spring"/>
<context:annotation-config/>

<!-- wire beans required for testing -->
<import resource="classpath*:/context.xml"/>

, spring load cucumber.xml, context.xml.

+5

All Articles