how to define step definitions location for cucumber in intelliJ 12
Solution 1
I was just tearing my hair out with exactly the same problem (for the record my background is Java, Ruby, Cucumber and RubyMine but I'm completely new to IntelliJ and Cucumber-JVM).
In the Cucumber-JVM run configuration
you must specify the package where the step definitions are stored in the glue
field as mentioned in the IntelliJ documentation. IntelliJ - for me at least - does not seem to provide a default value.
To elaborate further, a very basic project looks like this:
Example
└───src
├───main
│ └───java
└───test
├───java
│ └───com
│ └───bensnape
│ └───example
│ MyStepdefs.java
└───resources
example.feature
The glue
value here would be com.bensnape.example
.
Update
After playing with IntelliJ some more this morning, it seems that it does provide the glue
value for you if you adhere to the Cucumber-JVM conventions - i.e. the features must live under src/test/resources/<package>
and similarly, the steps must live under src/test/java/<package>
.
Example project tree:
Example
└───src
├───main
│ └───java
└───test
├───java
│ └───com
│ └───bensnape
│ └───example
│ MyStepdefs.java
│
└───resources
└───com
└───bensnape
└───example
example.feature
Solution 2
If you mark the folder as a (test) source root (right click folder -> Mark directory as -> (Test) Source Root) it will work as well.
My grails project is set up like this:
test
├───cucumber
│ └───steps
│ └───support
│ └───features
└───unit
Unit was marked as test source root, after also marking cucumber as one the step definitions were parsed correctly.
Solution 3
You can set the glue location globally by opening "Edit Configurations -> Defaults -> Cucumber Java -> Glue" and add the package names.
(IntelliJ 12.1.4)
Solution 4
The default convention is to have step definitions
defined in a step_definitions sub-folder
under the features directory
. The name of the sub-folder isn't important; it will work the same whatever the name is.
My guess is that an IDE would follow the same convention, and hence IntelliJ should execute the features correctly if the step_definitions folder is moved under features folder.
The cucumber command
takes a -r
option to require files before executing the features. This option can be used to make it look for step_definitions in a non-conventional place.
I am guessing you may have -r src/main/java/com/step_definitions
on your local configuration for cucumber to see these step_definitions when invoked from commandline.
Running cucumber --verbose
shows where the command line is finding the step definition code.
theawesome
Updated on July 09, 2022Comments
-
theawesome almost 2 years
I have my
feature files
insrc/resources/com/features
and mystep definitions
insrc/main/java/com/step_definitions
My tests all run correctly, but intelliJ refuses to see where the step defs are, even if I ask it to create a new one. Where is this configured?
-
theawesome over 11 yearsSo I've now refactored my code to look likethis This didn't seem to help. I have also gone to run configurations and entered com.step_definitions into the glue path (cucumber default config). I've not entered anything else here as not sure what to put Presumably this only affect the run, not the IDE?
-
theawesome over 11 yearsI tried moving my step definitions into features/step_definitions and it still doesn't seem to find them :(
-
theawesome over 11 yearsCuriously, it now picks up my step def files, and when I select the helper to create a step_definition, it gives me a list of my files where I can put it. However it still insists (even after putting a new method in the file) that the step def is undefined.
-
ben.snape over 11 yearsApologies I've been away on holiday. Did you manage to resolve your problem? If not, perhaps you could try updating the question with more information as it's difficult to see exactly the problems you're facing.
-
AA. over 10 yearsThis is the answer to my grails project. Thanks.