user11204869
user11204869

Reputation: 1

Cucmber Feature file execution from Maven CLI

I am trying to execute a cucumber feature file from maven command line and facing the following issue - Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test (default-test) on project Maven: No tests were executed!

The command I have used to execute is - mvn -Dtest -Document.options="src/test/resources/maven_poc/excel_colors.feature:3"

However the step definitions file is executed successfully when executed from maven command prompt. • mvn -Dtest=excel_color_stepdef test Screenshot at the link - https://i.sstatic.net/MKsd8.jpg

My pom.xml is as below. Anyone who has faced similar issues? Any tips on resolution steps is appreciated.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  
  <modelVersion>4.0.0</modelVersion>

  <groupId>Cucumber_POC</groupId>
  <artifactId>Maven</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

 <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  
<reporting>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jxr-plugin</artifactId>
         <version>2.3</version>
      </plugin>
   </plugins>
</reporting>
  
 <build>
	<defaultGoal>install</defaultGoal>
        <pluginManagement>
      		<plugins>
         		<plugin>
    			<groupId>org.apache.maven.plugins</groupId>
    			<artifactId>maven-surefire-plugin</artifactId>
   	 			<version>2.14.1</version>
    			<configuration>
        		<testFailureIgnore>true</testFailureIgnore>
        		</configuration>
				</plugin>  
				
		 		<plugin>
        		<groupId>org.apache.maven.plugins</groupId>
        		<artifactId>maven-install-plugin</artifactId>
       			<version>2.5.2</version>
 				</plugin>
 				
 				<plugin>
        		<groupId>org.apache.maven.plugins</groupId>
        		<artifactId>maven-jar-plugin</artifactId>
        		<version>2.4</version>
        		</plugin>
        		
        		<plugin>
  				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-site-plugin</artifactId>
  				<version>3.7.1</version>
				</plugin>
				
				<plugin>
  				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-project-info-reports-plugin</artifactId>
  				<version>3.0.0</version>
				</plugin>
				
		</plugins>
    </pluginManagement>      
</build>
		
  <dependencies>
   	
   	 	<dependency>
      	<groupId>junit</groupId>
      	<artifactId>junit</artifactId>
      	<version>4.12</version>
      	<scope>test</scope>
     	</dependency>
    
      	<dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>2.3.1</version>
        <scope>test</scope>
    	</dependency>
    
      	<dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>2.3.1</version>
        <scope>test</scope>
    	</dependency>
    
    	<dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>gherkin</artifactId>
        <version>5.1.0</version>
        <scope>test</scope>
    	</dependency>
    
     	<dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>2.3.1</version>
        </dependency>

		<dependency>
		<groupId>org.apache.poi</groupId>
		<artifactId>poi</artifactId>
		<version>4.0.1</version>
		</dependency>

		<dependency>
    	<groupId>org.apache.poi</groupId>
    	<artifactId>poi-ooxml</artifactId>
    	<version>4.0.1</version>
		</dependency>
        
		<dependency>
    	<groupId>org.apache.maven.plugins</groupId>
    	<artifactId>maven-surefire-plugin</artifactId>
    	<version>2.12.4</version>
  		</dependency>

		 <dependency>
         <groupId>org.junit.platform</groupId>
         <artifactId>junit-platform-surefire-provider</artifactId>
         <version>1.1.0</version>
         </dependency>
     
             
 </dependencies>
 
</project>

Upvotes: 0

Views: 209

Answers (2)

Allan Moreira Leite
Allan Moreira Leite

Reputation: 406

You should execute the java test class that references the cucumber. Something like:

@ContextConfiguration(loader = SpringBootContextLoader.class, classes = EligibilityApplication.class)
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/cucumber/eligibility/listpolicies/ListPolicies.feature", strict = true)
public class ListPoliciesTest {

}

And in the maven command you will use something like:

mvn -Dtest="src/test/java/../ListPoliciesTest.java"

Upvotes: 0

M.P. Korstanje
M.P. Korstanje

Reputation: 12019

Those don't look like valid maven commands. It's mvn test. And the system property is named cucumber.options. So mvn test -Dcucumber.options="src/test/resources/maven_poc/excel_colors.feature:3"

Upvotes: 2

Related Questions