Pages

What is Cucumber JUnit runner class

What is the Cucumber JUnit runner class?

In order to execute any scenario in cucumber, we have use cucumber uses JUnit annotation @RunWith(). As cucumber uses JUnit we have to create runner class(say Runner.java).In runner class we have to specify @RunWith() annotation, then which tells JUnit what is the runner class.

We can say @RunWith() annotation is like a starting point for JUnit to start executing our tests.
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"src/main/java/features/sample.feature"},
        glue = {"stepdefinitions"},
        plugin = {"pretty", "json:target/cucumber-reports.json", "html:src/output/report.html",
                "junit:target/cucumber-reports/cucumber.xml"},
        tags = "@smoke",
        monochrome = false)
public class Runner {
}
Cucumber Runner Class File
Cucumber Runner Class

Cucumber provides several options that can be used to execute our scenarios.

Below are few cucumberOptions will be used mandatory used:

features = specify a path to feature file or multiple feature files as well.

glue = specify a path to step definitions file(s)

plugin = provides an option for reporting purpose in HTML formats for easy readability

tags = executes the specified tagged scenarios only.

monochrome = prints cucumber console output in a readable format (with color) and by default, it is set to false.

Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.