繁体   English   中英

Maven Surefire 插件未启动 TestNG 套件 XML 文件中定义的测试

[英]Maven Surefire plugin not starting tests defined in TestNG suite XML file

我正在开发一个测试自动化项目,它使用:Maven、TestNG、Cucumber 和 ZC49DFB55F06BB5406E2C5CA7D3WebDriver。 我的操作系统是 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>

套件文件具有“RunnerAllFeatures”,因为它是测试 class。 当我手动启动该套件文件(右键单击并“运行”)时,它运行良好 - 正在执行“RunnerAllFeatures”中定义的 cucumber 场景。 跑步者 class “RunnerAllFeatures” 看起来像这样:

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”来做到这一点。 构建摘要状态为“构建成功”,但未运行任何测试。 日志行“TESTS”甚至不存在。 没有(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] ------------------------------------------------------------------------

我尝试在“suite.xml”的 POM 路径中将反斜杠更改为正斜杠,但它没有改变任何东西。 我试图参数化该路径,但结果是相同的。 我有另一个测试自动化项目,其中技术堆栈的唯一区别是缺少 Cucumber。 TestNG 套件文件指向带有“@Test”注释的 class。 通过 Maven Surefire 启动该套件文件在那里运行良好。

如果需要更多信息,我会尽力提供。

找到了解决方案。 Runner class 名称错误 - 它必须包含“Test”一词。 请参阅: https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html

我知道这个 Maven 命名约定,但我不怀疑这可能是一个问题,因为“RunnerAllFeatures”是一个跑步者 class 而不是测试 class。

暂无
暂无

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

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