maven - 无法使用 testng.xml 执行 Cucumber 功能文件
问题描述
我有 2 个功能文件,我想通过 testng 并行执行。如果我执行 mvn test 它显示 Build Success 但它不执行测试用例。有人可以帮忙吗?请在我的结构下面找到。
测试NG.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name = "FlipkartSmoke" verbose="1" thread-count="2" parallel="methods">
<test name = "FlipkartLogin">
<classes>
<class name="runner.testrunner">
</class>
</classes>
</test>
</suite>
testrunner.java:
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(
features="src\\test\\java\\features",
glue= {"seleniumGlueCode"},
format= {"html:target"},
monochrome=true,
dryRun=false
)
public class testrunner extends AbstractTestNGCucumberTests{
}
pom.xml:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<includes>
<include>TestNG.xml</include>
</includes>
</configuration>
</plugin>
pom.xml:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- ******************************************************************************** -->
<!-- Selenium Dependencies -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.7.0</version>
</dependency>
<!-- ******************************************************************************** -->
<!-- Cucumber Dependencies -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>13.0.0</version>
</dependency>
<!-- ******************************************************************************** -->
<!-- TestNG Dependencies -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.2.0</version>
</dependency>
<!-- ******************************************************************************** -->
<!-- Excel Read Dependencies -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.1</version>
</dependency>
<!-- ******************************************************************************** -->
<!-- Common io Dependencies -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
它显示构建成功。但它没有执行测试用例。但如果我尝试在 testrunner 中使用 @runWith 作为 junit 测试用例的意思,两个功能文件都在执行。
解决方案
我认为您正在将 JUnit 测试和 TestNG 测试与 Surefire 插件混合使用。即使您将“包含”与“suiteXmlFiles”混合在一起。所以我对你的建议是停止并阅读文档,编写几乎没有 Java 代码或最少代码的小 Maven 项目,并使用命令mvn test让 POM 正常工作。让基本项目正常工作并理解这一点非常重要。 https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html 盯着很多乱七八糟的依赖项和代码无论如何都会让你的头脑变得一团糟。因此,从基本人员开始。
推荐阅读
- html - HTML CSS: How to Make Div Box Height Equal Text Height?
- javascript - Adding Role Based Redirection Upon Login to React App
- html - Add textContent to HTML via MediaWiki template
- javascript - 从本地主机调用 api
- python - How to set the number of ticks and labels of pyplot
- oracle - Can not install Oracle database client 18c on win 10 32 bit
- arduino - 我的代码没有打开继电器模块中的所有四个通道
- java - Java:将参数传递给有界参数函数
- python - TF2.0 中的 saved_model.prune()
- c# - WPF ClickOnce 安装程序不包含来自 nuget 包的非托管 dll