Skip to main content

Execute Cucumber from Command Line Maven

To execute Cucumber command line from terminal using Maven you need to add Maven surefire plugin in your pom.xml file. Compiler version is also recommended.

Maven surefire Plugin: The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports in two different file formats Plain text files (.txt) XML files (.xml). To know the latest version and to get the more information about the Surefire plugin click here.

Maven Compiler Plugin: The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse. To read more click here.

<build>
    <pluginManagement>
      <plugins>
            <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>  
      
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>3.0.0-M4</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

To execute cucumber project, navigate to directory where pom.xml is located and type below command:

$ mvn test

Make sure your Runner class filename should starts or ends with Test keyword. Example filename: TestRunner.java or RunnerTest.java.

Submitted by tgoswami on August 30, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.