I have an application that was tested with Cucumber, but since upgrading (Cucumber 1.1.6 to 1.2.5, java 1.6 to 1.8, Spring 3.2.0 to 4.2.6) it no longer works because it complains about Annotations differs on glue classes found
The structure is as follows:
- Some common stepdefs which need some property values
- More specific stepdefs which require some
@ContextConfiguration
Both of these should also share a bean.
The common part will never be run on its own. But I have multiple tests each using their own specific stepdefs. This now refuses to run because of Annotations differs on glue classes found
.
Is there a way to get this to run without polluting the common context with the specifics of the concrete context?
The step definitions:
@ContextConfiguration("classpath:cucumber-common.xml")
public class CommonStepdefs {
@Autowired
private SharedBean sharedBean;
@Value("${some.property}")
private String someProperty;
// actual step def methods
}
@ContextConfiguration("classpath:cucumber-concrete.xml")
public class ConcreteStepdefs {
@Autowired
private SharedBean sharedBean;
@Autowired
private OtherBean otherBean;
// actual step def methods
}
The common Spring configuration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:com/example/cucumber-common.properties"/>
<context:spring-configured/>
<context:annotation-config/>
<bean id="glueCodeScope" class="cucumber.runtime.java.spring.GlueCodeScope"/>
<bean id="glueCodeScopeConfigurer" class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="cucumber-glue" value-ref="glueCodeScope"/>
</map>
</property>
</bean>
<bean id="sharedBean" class="com.example.SharedBean" scope="cucumber-glue"/>
</beans>
The other Spring configuration (which imports the common one):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="classpath:cucumber-common.xml"/>
<context:spring-configured/>
<context:annotation-config/>
<context:component-scan base-package="com.example.rest"/>
<!-- more bean definitions -->
</beans>
The tests are run using:
@RunWith(Cucumber.class)
@CucumberOptions(
format = { "html:target/cucumber-html-report", "json:target/cucumber-json-report.json" },
glue = { "com.example.common", "com.example.concrete" },
monochrome = true,
strict = true)