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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

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

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

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

Related

  • WebDriverIO Integration With Cucumber
  • COM Design Pattern for Automation With Selenium and Cucumber
  • Automating Cucumber Data Table to Java Object Mapping in Your Cucumber Tests
  • Integrate Cucumber in Playwright With Java

Trending

  • Event Driven Architecture (EDA) - Optimizer or Complicator
  • GitHub Copilot's New AI Coding Agent Saves Developers Time – And Requires Their Oversight
  • Scaling Microservices With Docker and Kubernetes on Production
  • Rust, WASM, and Edge: Next-Level Performance
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Scala: Cucumber From IntelliJ and the Command Line With SBT

Scala: Cucumber From IntelliJ and the Command Line With SBT

Want to bring your Cucumber tests to IntelliJ or the command line? Here is how to configure your architecture to make it easy for you.

By 
Fabio Serragnoli user avatar
Fabio Serragnoli
·
Jan. 31, 18 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
10.8K Views

Join the DZone community and get the full member experience.

Join For Free

In this post, we'll see how to have Cucumber tests running in IntelliJ and the command line using SBT.

Adding Cucumber to the project and how to configure SBT multi-module won't be covered this time, as these topics are well-covered elsewhere.

Motivation

Executing Cucumber tests from IntelliJ is necessary to help during development, as you just want to start your application and run the Cucumber tests right from the IDE.

Executing Cucumber tests on the SBT command line is useful when you want to add the Cucumber tests as part of your application deployment pipeline.

From this point, "test" means "Cucumber test".

Project Architecture

This post is based on a multi-module SBT project. The separation in this architecture allows running functional tests against the same application deliverable that will be eventually running in production. The module discussed in this post is rhAcceptance:

Image title

Before choosing to go with the fat JAR approach, I tried to configure the test to execute from its natural location: PROJECT_ROOT/rhAcceptance/src/test. Having Googled it quite extensively, it seems only "Scalatests" are found by default in SBT.

Image title

There are a couple of third-party plugins that enable Cucumber tests to be run as part of the sbt test goal. I haven't used them, as I am wary of depending on third-party plugins with few contributors and, in this case, it was cheap to solve the problem in the way described below.

The alternative solution was to move the tests (PROJECT_ROOT/rhAcceptance/src/main directory) and run it as a fat JAR.

Image title

Fat JARs in SBT

In order to get the build.sbt creating a fat JAR, I used the assembly plugin. Note that assembly.sbt goes into the SBT project directory.

Image title

Below is the SBT configuration in the rhAcceptance module that creates a fat JAR named acceptance.jar

Image title

For the setup above, just run sbt assembly and the fat JAR will be created in PROJECT_ROOT/rhAcceptance/target/scala-2.12.

Cucumber From IntelliJ

Don't forget to install the plugins: "Scala", "Cucumber for Java", and "Cucumber for Scala".

Create the Cucumber runner as the main function:

Image title

Run the above main with the following configuration:

Image title

The message "Test framework quit unexpectedly" may sound like the test run failed, but we can see that they were run successfully.

Image title

Cucumber From the Command Line

Note that --glue must point to the root package where your step definitions are located.

The last argument, classpath:uk.co.myproject, is the location of your feature files. classpath is necessary to load the feature files from inside the JAR.

Image title

Now we have the same tests run successfully from IntelliJ and the command line.

Cucumber (software) intellij Command (computing) Testing Scala (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • WebDriverIO Integration With Cucumber
  • COM Design Pattern for Automation With Selenium and Cucumber
  • Automating Cucumber Data Table to Java Object Mapping in Your Cucumber Tests
  • Integrate Cucumber in Playwright With Java

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!