Maven Surefire 插件未启动 TestNG 套件 XML 文件中定义的测试
Maven Surefire plugin not starting tests defined in TestNG suite XML file
我正在开发一个测试自动化项目,它使用:
Maven、TestNG、Cucumber 和 Selenium WebDriver。我的 OS 是 Windows 10,我使用 IntelliJ 作为我的 IDE.
我有一个看起来像这样的 pom.xml 文件(为了展示目的更改了项目名称):
<?xml version="1.0" encoding="UTF-8"?><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>org.example</groupId>
<artifactId>project-name</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.9.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>6.9.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>6.9.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.iban4j</groupId>
<artifactId>iban4j</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/TestSuites/suite.xml</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
如您所见,“suite.xml”的路径在 POM 中定义并且是正确的:
TestNG 套件“suite.xml”文件如下所示:
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="All Tests Suite" verbose="1">
<test name="Test">
<classes>
<class name="Runners.RunnerAllFeatures"/>
</classes>
</test>
</suite>
Suite 文件有“运行nerAllFeatures”作为测试 class。当我手动启动该套件文件(右键单击和“运行”)时,它运行良好 - 正在执行“运行nerAllFeatures”中定义的黄瓜场景。
运行ner class “运行nerAllFeatures” 看起来像这样:
package Runners;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(
features = {"src/test/resources/Features/completed"},
glue = {"StepDefinitions"},
monochrome = true,
plugin = {"pretty", "html:target/cucumber.html"}
)
public class RunnerAllFeatures extends AbstractTestNGCucumberTests{}
当我尝试在终端中通过 Maven 运行“suite.xml”时出现问题。我使用“mvn clean test”来做到这一点。构建摘要指出“构建成功”,但没有测试 运行。日志行“T E S T S”甚至不存在。没有(imo)对问题很重要的警告。
这是日志片段之一:
C:\Users\username\IdeaProjects\project-name>mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] -------------< org.example:project-name >--------------
[INFO] Building project-name 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ project-name ---
[INFO] Deleting C:\Users\username\IdeaProjects\project-name\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ project-name ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ project-name ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 39 source files to C:\Users\username\IdeaProjects\project-name\target\classes
[INFO] /C:/Users/username/IdeaProjects/project-name/src/main/java/baseMethods/BaseMethods.java: C:\Users\username\IdeaProjects\project-name\src\main\java\baseMethods\BaseMethods.java uses un
checked or unsafe operations.
[INFO] /C:/Users/username/IdeaProjects/project-name/src/main/java/baseMethods/BaseMethods.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ project-name ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 17 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ project-name ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 17 source files to C:\Users\username\IdeaProjects\project-name\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ project-name ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.108 s
[INFO] Finished at: 2021-12-29T13:46:30+01:00
[INFO] ------------------------------------------------------------------------
我尝试将 POM 路径中的反斜杠更改为“suite.xml”的正斜杠,但没有任何改变。
我试图对该路径进行参数化,但结果是一样的。我有另一个测试自动化项目,其中技术堆栈的唯一区别是缺少 Cucumber。 TestNG 套件文件指向注释为 class 的“@Test”。通过 Maven Surefire 启动该套件文件在那里工作得很好。
如果需要更多信息,我会尽力提供。
找到解决方案。 Runner class 名称错误 - 它必须包含单词“Test”。
参见:https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
我知道这个 Maven 命名约定,但我不怀疑这可能是这里的问题,因为“RunnerAllFeatures”是运行器 class 而不是测试 class。
我正在开发一个测试自动化项目,它使用: Maven、TestNG、Cucumber 和 Selenium WebDriver。我的 OS 是 Windows 10,我使用 IntelliJ 作为我的 IDE.
我有一个看起来像这样的 pom.xml 文件(为了展示目的更改了项目名称):
<?xml version="1.0" encoding="UTF-8"?><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>org.example</groupId>
<artifactId>project-name</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.9.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>6.9.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>6.9.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.iban4j</groupId>
<artifactId>iban4j</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/TestSuites/suite.xml</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
如您所见,“suite.xml”的路径在 POM 中定义并且是正确的:
TestNG 套件“suite.xml”文件如下所示:
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="All Tests Suite" verbose="1">
<test name="Test">
<classes>
<class name="Runners.RunnerAllFeatures"/>
</classes>
</test>
</suite>
Suite 文件有“运行nerAllFeatures”作为测试 class。当我手动启动该套件文件(右键单击和“运行”)时,它运行良好 - 正在执行“运行nerAllFeatures”中定义的黄瓜场景。 运行ner class “运行nerAllFeatures” 看起来像这样:
package Runners;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(
features = {"src/test/resources/Features/completed"},
glue = {"StepDefinitions"},
monochrome = true,
plugin = {"pretty", "html:target/cucumber.html"}
)
public class RunnerAllFeatures extends AbstractTestNGCucumberTests{}
当我尝试在终端中通过 Maven 运行“suite.xml”时出现问题。我使用“mvn clean test”来做到这一点。构建摘要指出“构建成功”,但没有测试 运行。日志行“T E S T S”甚至不存在。没有(imo)对问题很重要的警告。 这是日志片段之一:
C:\Users\username\IdeaProjects\project-name>mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] -------------< org.example:project-name >--------------
[INFO] Building project-name 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ project-name ---
[INFO] Deleting C:\Users\username\IdeaProjects\project-name\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ project-name ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ project-name ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 39 source files to C:\Users\username\IdeaProjects\project-name\target\classes
[INFO] /C:/Users/username/IdeaProjects/project-name/src/main/java/baseMethods/BaseMethods.java: C:\Users\username\IdeaProjects\project-name\src\main\java\baseMethods\BaseMethods.java uses un
checked or unsafe operations.
[INFO] /C:/Users/username/IdeaProjects/project-name/src/main/java/baseMethods/BaseMethods.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ project-name ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 17 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ project-name ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 17 source files to C:\Users\username\IdeaProjects\project-name\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ project-name ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.108 s
[INFO] Finished at: 2021-12-29T13:46:30+01:00
[INFO] ------------------------------------------------------------------------
我尝试将 POM 路径中的反斜杠更改为“suite.xml”的正斜杠,但没有任何改变。 我试图对该路径进行参数化,但结果是一样的。我有另一个测试自动化项目,其中技术堆栈的唯一区别是缺少 Cucumber。 TestNG 套件文件指向注释为 class 的“@Test”。通过 Maven Surefire 启动该套件文件在那里工作得很好。
如果需要更多信息,我会尽力提供。
找到解决方案。 Runner class 名称错误 - 它必须包含单词“Test”。 参见:https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
我知道这个 Maven 命名约定,但我不怀疑这可能是这里的问题,因为“RunnerAllFeatures”是运行器 class 而不是测试 class。