I have No Scope registered for scope name 'cucumber-glue'
error while running Cucumber (6.1.1) BDD tests with Spring
My configuration file
@ContextConfiguration(locations = {"classpath:/application-context-bdd.xml"})
@CucumberContextConfiguration
public class Configuration {
}
My test file
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {
"json:target/cucumber-json-report.json" },
glue = {"xx/java/bdd/configuration", "xx/java/bdd/stepdefs", "xx/java/bdd/steps"},
features = "classpath:features",
publish = false
)
public class TestBDD {
}
My application context file, where my cucumber-glue
bean is declared.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="todoRepository" scope="cucumber-glue"/>
<bean name="todoService" >
<constructor-arg ref="todoRepository"/>
</bean>
<bean name="todoStep" >
<constructor-arg ref="todoService"/>
</bean>
<bean > <!-- Not needed since @M.P. Korstanje reply -->
<constructor-arg ref="todoStep"/>
</bean>
</beans>
any idea ??
CodePudding user response:
The correct scope is cucumber-glue
but it only exists when a scenario is active. By defining a bean in the xml
it will be created when the application starts, before any scenario has started.
You don't need to define TodoStepDefinition
as bean though. Cucumber will created it as needed.
https://github.com/cucumber/cucumber-jvm/tree/main/spring#sharing-state
CodePudding user response:
the solution is to declare all todoRepository
depending beans in cucumber-glue
scope
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean name="todoRepository" scope="cucumber-glue"/>
<bean name="todoService" scope="cucumber-glue">
<constructor-arg ref="todoRepository"/>
</bean>
<bean name="todoStep" scope="cucumber-glue">
<constructor-arg ref="todoService"/>
</bean>
</beans>