Overriding Cucumber Options from Terminal

Profile picture for user devraj

When it is necessary to override the options mentioned in the JUnit Runner, then we need Dcucumber.options from the Terminal.

Let's look at some of the practical examples.

@CucumberOptions(

		plugin = {"pretty","html:target/cucumber"},
		features = {"features"},
		glue={"com.pb.cucumbertest.stepdefinitions"},
		monochrome = true,
		strict = true,
		dryRun = false,
		tags = {"@smoke"}
		)

This is a code of my Test Runner class, its executing @smoke test cases, to execute @regression test cases I need to replace this @smoke with @regression in my runner class. Every time I want to execute test cases with different tag, I need to modify my Test Runner class which is really bad practice when you are executing using Jenkins and pulling the code from git because every time you need to modify your code and then commit it to git. Even if you are doing it using command line, this would be a waste of time to modify test runner again and again.

Suppose, you want to execute @regression test case instead of @smoke then you need to write below command:

$ mvn test -Dcucumber.options="--tags @regression"

This will override my default Test Runner configuration and execute @regression test cases instead of @smoke.