How to run the Gherkin Test scenario using Cucumber with Java?

Running the scenario using Cucumber with Java, we write a class called a test runner. This is a special kind of JUnit class which reads feature files and then finds the glue code that it needs to execute them. After this, there is a need to configure a single test runner to run one or many feature files.

Let's see an example of what a test runner class actually looks like. 

In fact, a test runner is just an empty class, as we can see here, with a few annotations. The first one, RunWith Cucumber, tells JUnit to hand over control to Cucumber when it runs the tests. And the second one lets us specify configuration options such as where Cucumber should look for the feature files in the glue code. There are quite a few options that you can configure with the Cucumber runner, but probably the most important is the glue and features options. The glue option lets you define the package where Cucumber will look for your step definitions. By default, this will be the same package as your feature file, but many teams find it more readable to place their features in a meaningful directory structure under the src/test/features directory rather than in a Java package structure.

Your Answer


Parent Categories