DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • WebDriverIO Integration With Cucumber
  • AI-Driven Self-Healing Tests With Playwright, Cucumber, and JS
  • Integrating Redis With Message Brokers
  • Terraform State File: Key Challenges and Solutions

Trending

  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • AI Speaks for the World... But Whose Humanity Does It Learn From?
  • The Human Side of Logs: What Unstructured Data Is Trying to Tell You
  • Four Essential Tips for Building a Robust REST API in Java
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Running Cucumber From the Command Line

Running Cucumber From the Command Line

Learn the steps and conditions for running the Cucumber automated testing tool from the command line in this quick walkthrough.

By 
Jeroen Reijn user avatar
Jeroen Reijn
DZone Core CORE ·
Nov. 01, 17 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
35.2K Views

Join the DZone community and get the full member experience.

Join For Free

Recently, I’ve been spending some time with Cucumber and joined the Cucumber Gitter channel when somebody pointed out that they were having trouble running Cucumber from the command line. I usually run Cucumber from Maven, so I thought it would be interesting to see what was required to run cucumber from the command line.

As described in the documentation, you can run Cucumber features from the command line by using the CLI-runner with the following command:

java cucumber.api.cli.Main

You can get help by using the --help option:

java cucumber.api.cli.Main --help

This looks pretty straightforward if you are familiar with Java, but the "hard" part comes from understanding how to use the Java command with its classpath options.

One important aspect is that the cucumber.api.cli.Main class is located in the cucumber-core jar file, so when you want to run this class, you need to provide the cucumber-core jar on your classpath. In this case, I take the jar(s) from my Maven repository and include all required dependencies:

$ java -cp "/Users/jreijn/.m2/repository/info/cukes/cucumber-core/1.2.5/cucumber-core-1.2.5.jar:/Users/jreijn/.m2/repository/info/cukes/gherkin/2.12.2/gherkin-2.12.2.jar:/Users/jreijn/.m2/repository/info/cukes/cucumber-java/1.2.5/cucumber-java-1.2.5.jar:/Users/jreijn/.m2/repository/info/cukes/cucumber-jvm-deps/1.0.5/cucumber-jvm-deps-1.0.5.jar" cucumber.api.cli.Main

If you run this it should result in the following message:

Got no path to feature directory or feature file
0 Scenarios
0 Steps
0m0.000s

Now to be able to run we need to run a feature file you will need to provide two additional arguments:

  1. Your feature file(s)
  2. Your glue code (step definitions, hooks, etc)

Your feature files can be added to the end of the command line:

$ java -cp "/Users/jreijn/.m2/repository/info/cukes/cucumber-core/1.2.5/cucumber-core-1.2.5.jar:/Users/jreijn/.m2/repository/info/cukes/gherkin/2.12.2/gherkin-2.12.2.jar:/Users/jreijn/.m2/repository/info/cukes/cucumber-java/1.2.5/cucumber-java-1.2.5.jar:/Users/jreijn/.m2/repository/info/cukes/cucumber-jvm-deps/1.0.5/cucumber-jvm-deps-1.0.5.jar" cucumber.api.cli.Main Developer/sources/github/cucumber-jvm-extentreport/src/test/resources/cucumber/feature_one.feature

This will probably result in the following message:

UUUUUU

3 Scenarios (3 undefined)
6 Steps (6 undefined)
0m0.000s


You can implement missing steps with the snippets below:

[snip]

This means it can’t find the step definitions, hooks, etc that correspond to your feature file.

Let’s add the glue code required for running the tests. In the below example I’ll use my maven projects target directory, which contains my step definitions in the test-classes directory. You can do that by adding the directory to your classpath, and with the argument --glue com.sitture.definitions, provide the Java package that contains step definition Java classes.

$ java -cp "/Users/jreijn/.m2/repository/info/cukes/cucumber-core/1.2.5/cucumber-core-1.2.5.jar:/Users/jreijn/.m2/repository/info/cukes/gherkin/2.12.2/gherkin-2.12.2.jar:/Users/jreijn/.m2/repository/info/cukes/cucumber-java/1.2.5/cucumber-java-1.2.5.jar:/Users/jreijn/.m2/repository/info/cukes/cucumber-jvm-deps/1.0.5/cucumber-jvm-deps-1.0.5.jar:/Users/jreijn/Developer/sources/github/cucumber-jvm-extentreport/target/test-classes/" cucumber.api.cli.Main --glue com.sitture.definitions Developer/sources/github/cucumber-jvm-extentreport/src/test/resources/cucumber/feature_one.feature

This should result in something similar to:

......
....
.....

3 Scenarios (3 passed)
6 Steps (6 passed)
0m0.067s

Which seems about right and shows how we can run Cucumber from the command line with the Cucumber CLI.

Cucumber (software) Command (computing)

Published at DZone with permission of Jeroen Reijn. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • WebDriverIO Integration With Cucumber
  • AI-Driven Self-Healing Tests With Playwright, Cucumber, and JS
  • Integrating Redis With Message Brokers
  • Terraform State File: Key Challenges and Solutions

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!