Discussion:
[Cucumber] Cucumber not loading supporting classes
Add Reply
'Michael Cunningham' via Cukes
2018-11-05 16:37:48 UTC
Reply
Permalink
I have a Cucumber/Java project whose glue package is x.y.z

test.resources.features/dropDatabaseFeature.feature which makes use of
methods in the corresponding java steps code dropDatabaseSteps.java
test.resources.features/transferFileFeature.feature which makes use of
methods in the corresponding java steps code transferFileSteps.java

At test.java.x.y.z.databaseSteps/dropDatabaseSteps.java I use
@ContextConfiguration=CucumberConfig.class
At test.java x.y.z.fileSteps/transferFileSteps.java I use
@ContextConfiguration=CucumberConfig.class
and get an error saying both classes attempt to configure the spring
context. If only 1 class has the
@ContextConfiguration=CucumberConfig.class it works ok.

Since I do not want to hide the SpringContext setup in any one feature
file, since I will eventually have many, I created
test.java.x.y.z.SpringContextSetup.java, and empty class which had
@ContextConfiguration=CucumberConfig.class before the class statement.
This resulted in nullPointerException for the injected objects, so the
Spring container config was not being configured. Why is this? It because
there's no features file using the SpringContextSetup class and so the
class is not being loaded at runtime?
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Björn Rasmusson
2018-11-05 20:04:26 UTC
Reply
Permalink
Post by 'Michael Cunningham' via Cukes
I have a Cucumber/Java project whose glue package is x.y.z
test.resources.features/dropDatabaseFeature.feature which makes use of
methods in the corresponding java steps code dropDatabaseSteps.java
test.resources.features/transferFileFeature.feature which makes use of
methods in the corresponding java steps code transferFileSteps.java
Note, all step definitions in all glue classes are available to every
feature file. I say this because your conversion of collection all step
definitions used in one glue class most likely, sooner of later, will
result the both X.feature and Y.feature contain the step "Given Z", and
defining a step definition for the step "Given Z" in more than one glue
class will result in an error.
Post by 'Michael Cunningham' via Cukes
At test.java.x.y.z.databaseSteps/dropDatabaseSteps.java I use
@ContextConfiguration=CucumberConfig.class
At test.java x.y.z.fileSteps/transferFileSteps.java I use
@ContextConfiguration=CucumberConfig.class
and get an error saying both classes attempt to configure the spring
context. If only 1 class has the
@ContextConfiguration=CucumberConfig.class it works ok.
Since I do not want to hide the SpringContext setup in any one feature
file, since I will eventually have many, I created
test.java.x.y.z.SpringContextSetup.java, and empty class which had
@ContextConfiguration=CucumberConfig.class before the class statement.
This resulted in nullPointerException for the injected objects, so the
Spring container config was not being configured. Why is this? It because
there's no features file using the SpringContextSetup class and so the
class is not being loaded at runtime?
Only @ContextConfiguration annotations on glue classes are considered by
Cucumber-JVM. Glue classes are classes with, at least on, step definition
(Given, When, Then etc.) or hook (cucumber.api.java.Before,
cucumber.api.java.After etc). Your SpringContextSetup class must contain no
step definition or hook, otherwise its @ContextConfiguration had been used
by Cucumber-JVM.

/Björn
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Michael Cunningham' via Cukes
2018-11-12 10:02:47 UTC
Reply
Permalink
Many thanks Björn. Makes sense now. I moved @ContextConfiguration into more
general, shared CucumberHooks class.

Michael
Post by Björn Rasmusson
Post by 'Michael Cunningham' via Cukes
I have a Cucumber/Java project whose glue package is x.y.z
test.resources.features/dropDatabaseFeature.feature which makes use of
methods in the corresponding java steps code dropDatabaseSteps.java
test.resources.features/transferFileFeature.feature which makes use of
methods in the corresponding java steps code transferFileSteps.java
Note, all step definitions in all glue classes are available to every
feature file. I say this because your conversion of collection all step
definitions used in one glue class most likely, sooner of later, will
result the both X.feature and Y.feature contain the step "Given Z", and
defining a step definition for the step "Given Z" in more than one glue
class will result in an error.
Post by 'Michael Cunningham' via Cukes
At test.java.x.y.z.databaseSteps/dropDatabaseSteps.java I use
@ContextConfiguration=CucumberConfig.class
At test.java x.y.z.fileSteps/transferFileSteps.java I use
@ContextConfiguration=CucumberConfig.class
and get an error saying both classes attempt to configure the spring
context. If only 1 class has the
@ContextConfiguration=CucumberConfig.class it works ok.
Since I do not want to hide the SpringContext setup in any one feature
file, since I will eventually have many, I created
test.java.x.y.z.SpringContextSetup.java, and empty class which had
@ContextConfiguration=CucumberConfig.class before the class statement.
This resulted in nullPointerException for the injected objects, so the
Spring container config was not being configured. Why is this? It because
there's no features file using the SpringContextSetup class and so the
class is not being loaded at runtime?
Cucumber-JVM. Glue classes are classes with, at least on, step definition
(Given, When, Then etc.) or hook (cucumber.api.java.Before,
cucumber.api.java.After etc). Your SpringContextSetup class must contain no
by Cucumber-JVM.
/Björn
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...