Setting up cucumber and sbt in IntelliJ

If you want to look into a starter project where cucumber feature file can be run right from IntelliJ IDEA with sbt as a build tool, this blog is a perfect match.  I will put the below ingredients and complete recipe on how to write a feature file and plug it in with your implementation steps in IntelliJ IDEA.

Ingredients:

build.sbt

sbt-cucmber-1.png

First three lines may vary as per your application. The last third lines are mandatory to have cucumber plugins for scala and JUnit which will be used as Runner for the feature files.

IntelliJ IDEA plugins:

You will need to install the below plugins in your IDEA. Go to Files >> Settings >> Plugins in you IDEA and browse the repositories for the below plugins and install them.

  1. Cucumber for Java
  2. Cucumber for Scala
  3. Gherkin

sbt-cuke-2

Recipe:

 Writing Feature Files:

.feature files are specifications or behaviors in BDD. I assume you are already familiar with cucumber terms. You can place your feature files under any package in the project but it is recommended to place them under test directory.

sbt-cucumber-3

 Adding Feature Steps:

To give your features executables code on eas step, The step implementations are required. Each implementation contains reg-ex for equivalent feature steps. A step may or may not contain arguments. All of the feature steps are contained in the Runner class to run feature file as a Test Suite. Below is the example of a runner. It contains the step definition of the above feature file.

sbt-cucumber-4

Setting Run Configuration:

Before running, you need to edit the run configuration. In IDEA, go to Run >> Edit Configurations >>  Select “Defaults” and specify the  (a) glue (the path for feature steps) , (b) feature file path and (c) Main class  in respective fields:

sbt-cuke-5

Running Features:

Now, you can right-click on a feature or Scenario and run it right from your IDE.

Screenshot from 2018-07-09 16-18-36

Output:

Since the steps are not implemented yet, You will get NotImplemented exceptions as result below. The failing steps would be skipped.

Screenshot from 2018-07-09 16-24-13

Once you implement these steps and add assertions, you will get these feature file as passed.

Screenshot from 2018-07-09 16-22-39

You can find the source of the example codes on the GitHub at https://github.com/knoldus/sbt-cucumber. Hope you got what you wanted out of this blog. Comments are welcome!

 


knoldus-advt-sticker

 

Written by 

Manish Mishra is a Sr. Software Consultant, with experience of more than 7 years. His primary development technology was Java. He fell for Scala language and found it innovative and interesting language and fun to code with. He has also co-authored a journal paper titled: Economy Driven Real Time Deadline Based Scheduling. His interests include: learning cloud computing products and technologies, algorithm designing. He finds Books and literature as favorite companions in solitude. He likes stories, Spiritual Fictions and Time Traveling fictions as his favorites.

Leave a Reply

%d bloggers like this: