繁体   English   中英

运行Maven测试时未执行黄瓜测试

[英]Cucumber tests not executing when running maven test

我有一个黄瓜项目。 当我右键单击RunnerTest类并“运行“ RunnerTest”时,功能文件中的所有功能开始运行。所有测试均通过。

我的RunnerTest.class

   import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import java.sql.SQLException;
import lombok.extern.log4j.Log4j2;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
features = {"classpath:foo.feature"},
glue = "com.foo.foobar.StepDefinitions",
plugin = {"json:target/cucumber-report/cucumber.json"},
monochrome = true,
strict = true
//,dryRun = true
)

@Log4j2
public class RunnerTest {}

但是,当我尝试运行mvn test或mvn时,干净安装功能未运行。 这是输出。


试验

运行TestSuite使用以下方法配置TestNG:org.apache.maven.surefire.testng.conf.TestNG652Configurator@515f550a测试运行:0,失败:0,错误:0,跳过:0,经过时间:0.895秒

结果:

测试运行:0,失败:0,错误:0,跳过:0

这些是我的POM依赖项

<dependency>
  <groupId>io.cucumber</groupId>
  <artifactId>cucumber-junit</artifactId>
  <version>3.0.0</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>io.cucumber</groupId>
  <artifactId>cucumber-core</artifactId>
  <version>3.0.0</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>io.cucumber</groupId>
  <artifactId>cucumber-java</artifactId>
  <version>3.0.0</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>io.cucumber</groupId>
  <artifactId>cucumber-jvm</artifactId>
  <version>3.0.0</version>
  <type>pom</type>
</dependency>
<dependency>
  <groupId>io.cucumber</groupId>
  <artifactId>cucumber-jvm-deps</artifactId>
  <version>1.0.6</version>
</dependency>
<dependency>
  <groupId>io.cucumber</groupId>
  <artifactId>gherkin</artifactId>
  <version>4.1.3</version>
</dependency>
<!--<dependency>-->
  <!--<groupId>junit</groupId>-->
  <!--<artifactId>junit</artifactId>-->
  <!--<version>4.12</version>-->
<!--</dependency>-->
<dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.14.3</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <version>1.18.6</version>
  <scope>test</scope>
</dependency>

我试图添加mvn surefire插件,并在其中包括我的RunnerTest类。

<build>
 <pluginManagement>
  <plugins>
   <plugin>
     <artifactId>maven-surefire-plugin</artifactId>
     <version>2.12.4</version>
     <configuration>
       <includes>
       <include>RunnerTest.java</include>
       </includes>
     </configuration>
   </plugin>
  </plugins>
 </pluginManagement>
</build>

但这也不起作用

已知问题:如果并行保持Junit和TestNG两个依赖关系,则TestNG依赖关系将导致Surefire忽略JUnit包装器类。

解决方案:可能有多种处理方式,例如我们可以定义2个执行,每种分别用于TestNG和JUnit,并根据需要禁用一个。

您能尝试一下吗:请删除任何直接/间接的TestNG依赖项。

org.testng testng 6.14.3测试

并尝试添加以下一个-

io。黄瓜黄瓜试3.0.0

另外,我建议您再做一件事以保持pom.xml的干净。

关键点 :

  • 我们将不混合直接和传递依赖,特别是它们的版本! 这样做可能导致不可预测的结果。

通过JUnit进行黄瓜执行

您应删除小黄瓜芯,小黄瓜java,小黄瓜jvm,小黄瓜jvm-deps,小黄瓜,因为它们是传递性依赖,当您添加以下直接(主)依赖时,Maven会添加这些依赖。 只需添加下面的2和上面共享的testng一个。

 <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>3.0.0</version>
</dependency>

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>3.0.0</version>
</dependency>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM