Test Runner Class in Cucumber

Profile picture for user devraj

Once you have defined your test cases and associated step definitions, you can run your test cases using several methods. One way to achieve this is using JUnit Test Runner Class.

For this we need to create new class which will use JUnit annotation @RunWith(), which tells JUnit that current class is the test runner class. When a class is annotated with @RunWith or extends a class annotated with @RunWith, JUnit will invoke the class it references to run the tests in that class instead of the runner built into JUnit.

@RunWith annotation tells JUnit that test should run using cucumber class which is present in io.cucumber.junit.Cucumber package.

Cucumber JUnit Runner Class

Create a new class with name Runner.java, and paste below code.

import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

		plugin = {"pretty", "html:target/cucumber"},
		features = {"features"},
		monochrome = true,
		tags = {"@contactus"},
		dryRun = false,
		strict = true

public class Runner {


Give path of your feature file in "features" and package name of your step definitions in "glue". @CucumberOptions will be explained in more detail in next tutorial.

Next step is right click on your runner class and execute it using Run As->JUnit Test.

You can also run it other eclipse IDE feature like run button on top.