How to link feature and step definition in cucumber

user85 picture user85 · Oct 8, 2014 · Viewed 25.5k times · Source

I'm new to Cucumber java and had this problem in initial stages: I'm not using MAVEN project for some reason. I just created a simple java project in eclipse.

I have my features under "src/dummy/pkg/features", and my implementation "StepDef.java" is under "src/dummy/pkg/features/implementation"

I have written step definitions for Given, When, and Then, but when I run my features file, it is unable to recognize the implementation. How do I link the features with step definitions?

Answer

Bala picture Bala · Oct 8, 2014

create a class YourClass and it would look something like the below and run it as JUnit test.

@RunWith(Cucumber.class)

@CucumberOptions(  monochrome = true,
                     features = "src/dummy/pkg/features/",
                       format = { "pretty","html: cucumber-html-reports",
                                  "json: cucumber-html-reports/cucumber.json" },
                         glue = "your_step_definition_location_package" )

public class YourClass {
  //Run this from Maven or as JUnit
}