How Do You Run Cucumber JUnit Tests With Maven?

Timothy Joseph | November 29, 2021

How Do You Run Cucumber JUnit Tests With Maven?

 

This is a frequent task that QA engineers undergo while developing a BDD automation test cases using Cucumber-JUnit. Maven provides us with the following basic structure for the test automation project.

image-1

In the above project structure, we have a page class (Page.java) corresponding to a step definition file (StepDefDemo.java) and a feature file (testDemo.feature). For executing the Cucumber-junit project, we need a test runner class (TestRunner.java) in test/java package, like the following:

image-2

Here, we have annotations in the Runner class like @RunWith which tells the Junit to run feature files with Cucumber-JUnit dependency, whereas @CucumberOptions configures the reporting style with the pretty plugin and the location for feature files & step-definition files. In the Runner file, we can also specify a particular section of the feature file to execute using @tag annotation.

 

Here's how you can run your feature files:

  • Directly run the runner class like Run As Junit Test
  • Run with Maven
    • Right-click on pom.xml then Run As Maven Test
    • Open project in console =, then run the command 'mvn test' (Command Line)

Have questions or concerns about test automation and need reliable QA resources, contact QASource's testing experts today.

Disclaimer

This publication is for informational purposes only, and nothing contained in it should be considered legal advice. We expressly disclaim any warranty or responsibility for damages arising out of this information and encourage you to consult with legal counsel regarding your specific needs. We do not undertake any duty to update previously posted materials.

Post a Comment

Categories