Multiple step definitions with spring context
See original GitHub issueThis check
public boolean addClass(final Class<?> stepClass) {
if (!stepClasses.contains(stepClass)) {
checkNoComponentAnnotations(stepClass);
if (dependsOnSpringContext(stepClass)) {
if (stepClassWithSpringContext != null) {
throw new CucumberException(String.format("" +
"Glue class %1$s and %2$s both attempt to configure the spring context. Please ensure only one " +
"glue class configures the spring context", stepClass, stepClassWithSpringContext));
}
stepClassWithSpringContext = stepClass;
}
stepClasses.add(stepClass);
}
return true;
}
in SpringFactory actually prevents usage of multiple step definitions which have to use spring context.
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Is there a way to reuse cucumber steps from multiple projects ...
When using cucumber-spring Cucumber uses Spring's TestContextManager framework. This framework starts a test context using a single class.
Read more >Sharing State Between Cucumber Step Definitions Using Java ...
In this article, let us see how we can simplify sharing state between various step definitions using a Singleton enum named TestContext. Let...
Read more >How to share the Spring Boot context between steps...
Hi all, I am working on a cucumber integration test project for spring boot. Currently I have only one feature file, and I...
Read more >Java Cucumber Tutorial 13 (Multiple Step Definition Classes)
Java Cucumber Tutorial 13 ( Multiple Step Definition Classes) | QAShahinJava Cucumber video tutorial on managing multiple Step Definition ...
Read more >Sharing state between steps in Cucumber-JVM using Spring
A small example in two parts ... Lets look at a small example and see how it can be implemented with one step...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I fixed it by doing the following…
A separate cucumber runner class:
and a context loader class
Afterwards you can implement your step definitions and split them by their concerns. But make sure that
ContextLoader
is in the same package as the step definitions are, in my casecom.whatever.feature.steps
Because it’s good programming style to keep responsibilities separated. Not only sourcecode but also tests should follow SRP.
E.g. a feature file for Login, another feature file for registration, another feature file for doing something meaningful. So we already separate the features into separate feature files, The same should be done with the step definition. Instead of having one huge step definition which handles all different features, it should be separated by it’s responsibility.