Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to define step definitions location for cucumber in intelliJ 12

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?

like image 737
theawesome Avatar asked Dec 21 '12 16:12

theawesome


People also ask

Where does Cucumber look for step definitions?

inside the directory in which Cucumber is run is treated as a step definition. In the same directory, Cucumber will search for a Feature corresponding to that step definition. This is either the default case or the location specified with the relevant relevant relevant -r relevant option.

How do you define step definitions in cucumbers?

Add a Step Definition file 1) Create a new Class file in the 'stepDefinition' package and name it as 'Test_Steps', by right click on the Package and select New > Class. Do not check the option for 'public static void main' and click on Finish button. Take a look at the message in the console window.

How do I add Cucumber configuration in Intellij?

From the main menu, select Run | Edit Configurations. or press Alt+Insert and select Cucumber Java from the list. After that, you can complete the configuration using the options on the right. For the description of each option, refer to Run/Debug configuration: Cucumber Java.


1 Answers

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
like image 91
ben.snape Avatar answered Oct 06 '22 18:10

ben.snape