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.
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.
- Cucumber for Java
- Cucumber for Scala
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.
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.
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:
Now, you can right-click on a feature or Scenario and run it right from your IDE.
Since the steps are not implemented yet, You will get NotImplemented exceptions as result below. The failing steps would be skipped.
Once you implement these steps and add assertions, you will get these feature file as passed.
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!