Run Cucumber Test from Maven Command Line


To have a successful and effective implementation of a test framework, it is always advisable that the test framework supports test execution in multiple ways.
The 2 most commonly used ways to execute tests in Cucumber Framework are by running the tests using JUnit and Maven.

To execute tests using JUnit, we need to create a JUnit Test Runner. Whereas, we need a Maven project to execute Cucumber tests from Command-Line.

Create a Maven project and add the below-mentioned dependencies to your Maven project.

 <!-- -->

<!-- -->

<!-- -->

<!-- -->


Run Test from Command Line

1. Open the command prompt and change the directory to the project location where pom.xml is present.

cd C:\Users\Vibha\eclipse-workspace-test\demo

2. All feature files should be in src/test/resources and create the Cucumber Runner class as CucumberRunnerTest.
Note:- The Runner class name should end with Test to execute the tests from Command Line
Run the following command in the command prompt:

mvn test

mvn test runs Cucumber Features using Cucumber’s JUnit Runner. The @RunWith (Cucumber.class) annotation on the TestRunner class tells JUnit to start Cucumber. Cucumber runs time parses the command-line options to know what feature to run, where the Glue Code lives, what plugins to use, and so on.

3. The below screenshot shows that CucumberRunnerTest class is triggered.

4. The below screenshot shows the build success output.

Overriding Cucumber Options

Cucumber provides several options that can be passed to on the command line.

1. Running Scenarios using Tags from Command Line

If you are using Maven and want to run a subset of scenarios tagged with @ValidCredentials.

mvn test -Dcucumber.filter.tags="@ValidCredentials"

There is one more way to execute Cucumber tests with tags

mvn test -Dcucumber.options="--tags @ValidCredentials"

2. Running a Feature file from Command Line

Suppose you want to run a single Feature File from the command line, then use the below syntax

mvn test -Dcucumber.options="src/test/resources/features/CucumberTagsExample.feature"

3. Creating Cucumber Report from Command Line

If we want to generate a different report, then we can use the following command and see the JUnit report generate at the location mentioned:

mvn test -Dcucumber.options="--plugin junit:target/cucumber-reports/cucumberReport.xml

4. Passing multiple Parameter from Command Line

If we want to pass more than one parameter, then we can use the following command

mvn test -Dcucumber.options="src/test/resources/features/CucumberTagsExample.feature" -Dcucumber.filter.tags="@InValidCredentials"

5. Running a Scenario without a tag from Command Line

If we want to run a single Scenario from the command line and no tag is assigned to that scenario, this is how we specify

 mvn test -Dcucumber.options="src/test/resources/features/CucumberTagsExample.feature:12"

That’s it! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!

In the next tutorial, I explained to run Cucumber Gradle tests from Command Line.


4 thoughts on “Run Cucumber Test from Maven Command Line

    1. I have tried and we can run a feature file from commandline with version 7.3.1 using same command : mvn test -Dcucumber.options=”src/test/resources/features/Login.feature”. To run a particular tag, this command works : mvn test -Dcucumber.filter.tags=”@InvalidCredentials”


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s