how to define step definitions location for cucumber in intelliJ 12
Asked Answered
R

5

10

I have my feature files in src/resources/com/features and my step definitions in src/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?

Ripple answered 21/12, 2012 at 16:11 Comment(0)
D
13

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
Dulcinea answered 28/12, 2012 at 21:45 Comment(3)
So 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?Ripple
Curiously, 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.Ripple
Apologies 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.Dulcinea
G
4

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.

Glottology answered 25/1, 2013 at 10:47 Comment(0)
T
3

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.

Trellis answered 22/12, 2012 at 4:42 Comment(1)
I tried moving my step definitions into features/step_definitions and it still doesn't seem to find them :(Ripple
P
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)

Prophecy answered 6/2, 2014 at 10:34 Comment(0)
P
0

I was having the same problem with version 12.1.3. My folders and files are set out in the standard way as described by the other answers and marking the code as a test source did not resolve it.

Then I updated to 12.1.6 the problem was fixed :)

Parra answered 25/10, 2013 at 13:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.