Cucumber for Java and Groovy in IntelliJ IDEA 12

Inspired by support for Cucumber in RubyMine and by Aslak’s suggestions, we’ve added Cucumber support for Java and Groovy.

With IntelliJ IDEA 12 now it’s easy to navigate from a step to its definition, look for a step’s usage and run .feature tests.

Here I’ll briefly describe how you can create a scenario, step definitions in Java and run a Cucumber test.

Let’s start with the java-calculator project from Cucumber-JVM’s examples. Suppose we want to create a scenario to test the subtraction.

We open basic_arithmetic.feature and write the following scenario:

Scenario: Subtraction
When I subtract 5 from 9
Then the result is 4

The IDE will highlight the step “When I subtract 5 from 9″ immediately, because there is no such definition:

A quick-fix will propose to create a step definition:

We select a class that would be the container of the new step definition, and press Enter. IntelliJ IDEA will create a template with the step definition:

Now we are ready to implement the logic.

The next step is to run the file basic_arithmetic.feature. Let’s open it and select Run Feature: basic_arith… from the context menu:

After the run console window appears, you can see the results:

Cucumber for Java and Groovy is available in IntelliJ IDEA 12 Preview for free download and evaluation.

As always, your suggestions and feedback are very much welcome in our issue tracker.

Develop with Pleasure!

About Andrey Cheptsov

Andrey Cheptsov is IntelliJ IDEA product marketing manager at JetBrains. He's passionate about productivity, programming languages and tools.
This entry was posted in New Features and tagged , . Bookmark the permalink.

20 Responses to Cucumber for Java and Groovy in IntelliJ IDEA 12

  1. jtonic says:

    Useful feature for IDEA

    I’ve tried the example in IDEA Leda 12 122.746 and I came across a NPE (see http://youtrack.jetbrains.com/issue/IDEA-93072), so I didn’t manage to create a step definition.

    Regards

  2. Max says:

    Great work! It also does auto-complete of scenario steps! Go Cucumber!

  3. Bill Wright says:

    I just downloaded the Community Edition 12 because of this increased cucumber support (I use the Ultimate Edition 11 now). These cucumber enhancements seem to be listed for either version. Yet when I bring up my existing cucumber project I see no sign of any cucumber integration at all. Not even syntax highlighting.

  4. Michael Dwyer says:

    I too am missing the highlighting, just downloaded the latest Community edition.

  5. Priya says:

    I am using intellij ldea ultimate edition 12
    Scenario-Not able to use double quotes in the middle of string:
    While writing scenarios I am not able to add double quotes in the mid of string.Is there any special character required to append with double quotes?
    eg:Scenario:concatenation
    And string “He”ll”o” added to string “World2″

  6. Gareth Fleming says:

    Although Cucumber support is listed in the feature list published on the main site for both versions of the IDE, the feature list on the EAP site (http://confluence.jetbrains.net/display/IDEADEV/IDEA+12+EAP) would suggest that Cucumber support is only available in Ultimate.

  7. Jonas says:

    I have Cucumber integration working for feature files that are written in English (using the English Gherkin keywords: Feature, Scenario, Given, When, Then …).

    However I can’t get the integration working with feature files that are written in another language. i.e. German (using the German Gherkin keywords: Funktionalität, Szenario, Wenn, Dann …).

    Example:
    https://github.com/cucumber/cucumber/blob/master/examples/i18n/de/features/addition.feature

    Are non-english feature files supported? How?

    Thanks for the info.

  8. Alex says:

    Is it possible to get some clarification on what edition ‘Cucumber for Java and Groovy’ is or will be in? When I look at the comparison matrix, Cucumber support is not even listed (for either edition). Thanks.

    http://www.jetbrains.com/idea/features/editions_comparison_matrix.html

  9. Andrey Cheptsov says:

    @Alex, Cucumber for Java and Groovy is only available in Ultimate at the moment. We will fix the comparison matrix page shortly.

  10. Divya Ashok says:

    Will Cucumber integration be available for the community edition anytime ?

  11. Paul says:

    Hi, I’m trying to get the Cucumber support working in IntelliJ IDEA 12.0.4 Ultimate. My features are not recognized (no syntax highlighting) in an existing project, and when creating a new Maven project (with Cucumber for Java plugin enabled), and adding the Cucumber dependencies, there is still no recognition. All the pages I found by googling imply that “it just works”, but I don’t see it so far. Anything else I need to do?

  12. Paul says:

    Following on from my comment yesterday, I found that the pattern “*.feature” was not assigned to the “Cucumber scenario files” file type (in Settings -> File Types). When I assigned it correctly, it works fine.

  13. Rogelio says:

    In my settings *.feature is correctly assigned to Cucumber but still loose the highlight and support on them. Had it working previously but lost it after a module re-import.
    Using #language: es and #encoding: utf-8 on the file but don’t think this matters.

  14. Anatoly says:

    I’d like to ask you to vote for the feature you are talking about here:
    http://youtrack.jetbrains.com/issue/IDEA-89738

  15. Bill Wright says:

    The Cucumber integration works nicely in the full version, but there is a serious drawback – or at least I don’t know how to work around it. I want to re-use steps from a dependency jar and I list that in my Maven dependencies and can run the cucumber scenarios fine, as long as I use a JUnit runner class and specify the class path to the step classes. Is there a way to specify this class path to step classes within the IDE as well? Right now IntellliJ seems to only find steps defined in the module itself. I’d love a way to work around this and it would make this feature useful to me. As it stands, it is only a slick demo and not a real-world feature for me.

  16. Bill Wright says:

    Actually, this is more complicated than I thought. You can specify where to find step classes and you do this via the run configuration via the “glue” field, which must be set but is not set automatically by IntelliJ, even when it creates the Step class for you. Once I manually set this glue field to the local package (the one used by IntelliJ when it automatically creates a step class for you) and any external packages (specified via Maven dependencies in my case), then when I run the scenario, steps are found and executed in both packages. That’s great, but the syntax highlighting of which steps are found and the step completion ONLY works on the local Steps class. So it will look like external steps are not defined, even though they are and will run fine when you run the scenario. It would be great if you could IntelliJ about external packages to search for steps…

  17. Nick Evgeniev says:

    great job! IT DOESN’T EVEN INSTALL ON MAC!

  18. Ole Christian Langfjæran says:

    Are there any plans or roadmap of having this feature for Scala also?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">