Software Development and QA Tips By QASource Experts

How Do You Run Cucumber JUnit Tests With Maven?

Written by Timothy Joseph | Nov 29, 2021 5:00:00 PM

 

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.

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:

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.