【问题标题】:Cucmber Feature file execution from Maven CLI从 Maven CLI 执行 Cucumber 功能文件
【发布时间】:2019-03-14 18:33:10
【问题描述】:

我正在尝试从 maven 命令行执行黄瓜功能文件并面临以下问题 - 无法执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test (default-test)在 Maven 项目上:未执行任何测试!

我用来执行的命令是—— mvn -Dtest -Document.options="src/test/resources/maven_poc/excel_colors.feature:3"

但是,当从 maven 命令提示符执行时,步骤定义文件会成功执行。 • mvn -Dtest=excel_color_stepdef 测试 链接截图 - https://i.stack.imgur.com/MKsd8.jpg

我的 pom.xml 如下。有谁遇到过类似的问题?感谢您提供有关解决步骤的任何提示。

<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>

【问题讨论】:

    标签: maven cucumber


    【解决方案1】:

    那些看起来不像是有效的 Maven 命令。这是mvn test。并且系统属性被命名为cucumber.options。所以mvn test -Dcucumber.options="src/test/resources/maven_poc/excel_colors.feature:3"

    【讨论】:

    • 感谢您的回复。我尝试执行您共享的命令,但仍然给出相同的错误:无法执行目标 - 未执行任何测试。
    • 抱歉,结果有更正。执行 mvn test -Dcucumber.options="src/test/resources/maven_poc/excel_colors.feature:3" 时构建成功。但未检测到测试。
    • 我不知道;那时不知道。你可以试试这个项目:github.com/cucumber/cucumber-java-skeleton 众所周知它可以工作。然后把它改到你的项目中,直到它停止工作,看看你哪里出错了。
    【解决方案2】:

    您应该执行引用黄瓜的 java 测试类。比如:

    @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 {
    
    }
    

    在 maven 命令中,您将使用如下内容:

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

    【讨论】:

    • 嗨艾伦,是的,你是对的,需要执行步骤定义文件。我已经成功执行了同样的操作,它也执行了测试。仅当我尝试从 maven 命令提示符执行功能文件时才报告问题。
    猜你喜欢
    • 2018-11-07
    • 1970-01-01
    • 2020-11-02
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    相关资源
    最近更新 更多