无法编译 TestNG 测试套件(Maven+Surefire)

Posted

技术标签:

【中文标题】无法编译 TestNG 测试套件(Maven+Surefire)【英文标题】:Can't compile TestNG test suite (Maven+Surefire) 【发布时间】:2021-06-26 05:39:30 【问题描述】:

我正在尝试从命令行“mvn clean test”运行测试套件

但我收到如下错误:

[错误] 无法在项目自动化上执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.20:test (default-test):有测试失败。 [错误] [错误] 个别测试结果请参考 C:\Users\Vartotojas\Desktop\Automatiniai testia\automation\target\surefire-reports。 [错误] 请参考转储文件(如果有)[日期]-jvmRun[N].dump、[日期].dumpstream 和[日期]-jvmRun[N].dumpstream。 [错误] 分叉进程中出现错误 [错误] 套件文件 C:\Users\Vartotojas\Desktop\Automatiniai testia\automation\AllTestsRelease.xml 不是有效文件 [ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: 分叉进程出错

这是我的完整 POM.xml 文件:

<groupId>automation</groupId>
<artifactId>automation</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
    <sourceDirectory>src/main</sourceDirectory>
    <testSourceDirectory>src/test</testSourceDirectory>
    <resources>
        <resource>
            <directory>src/resources</directory>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>
                src/testResources
            </directory>
            <filtering>true</filtering>
        </testResource>
    </testResources>

    <pluginManagement>
        <plugins>

            <plugin>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-maven</artifactId>
                <version>2.9</version>
                <configuration>
                    <reportVersion>2.6.0</reportVersion>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>$maven-surefire-plugin.version</version>
                <configuration>
                    <!--<testFailureIgnore>true</testFailureIgnore>-->
                    <useSystemClassLoader>false</useSystemClassLoader>
                    <threadCount>1</threadCount>
                    <suiteXmlFiles>
                        <suiteXmlFile>AllTestsRelease.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>$aspectj.version</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<properties>
    <xmlName>tst</xmlName>
    <maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <aspectj.version>1.9.2</aspectj.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <log4j.version>1.2.17</log4j.version>
    <sel4j.version>1.7.25</sel4j.version>
    <glassfish.version>2.26-b03</glassfish.version>
    <allure-testng.version>2.6.0</allure-testng.version>
    <ashot.version>1.5.4</ashot.version>
    <extentReport.version>2.41.2</extentReport.version>
    <jsonSimple.version>1.1.1</jsonSimple.version>
    <testng.version>6.9.10</testng.version>
    <io.appium>4.1.2</io.appium>
    <selenium.version>3.14.0</selenium.version>
    <webdriver.download>3.6.1</webdriver.download>
    <extentreports.version>4.0.9</extentreports.version>
    <org.json>20180813</org.json>
</properties>
<dependencies>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>$org.json</version>
    </dependency>
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports</artifactId>
        <version>$extentreports.version</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>$log4j.version</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>$sel4j.version</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>$glassfish.version</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.connectors</groupId>
        <artifactId>jersey-apache-connector</artifactId>
        <version>$glassfish.version</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>$glassfish.version</version>
    </dependency>
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-testng</artifactId>
        <version>$allure-testng.version</version>
    </dependency>
    <dependency>
        <groupId>ru.yandex.qatools.ashot</groupId>
        <artifactId>ashot</artifactId>
        <version>$ashot.version</version>
    </dependency>
    <dependency>
        <groupId>com.relevantcodes</groupId>
        <artifactId>extentreports</artifactId>
        <version>$extentReport.version</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>$jsonSimple.version</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>$testng.version</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>$selenium.version</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>$selenium.version</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>$selenium.version</version>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>$webdriver.download</version>
    </dependency>
    <dependency>
        <groupId>org.apache.pdfbox</groupId>
        <artifactId>pdfbox</artifactId>
        <version>2.0.15</version>
    </dependency>
</dependencies>

如果我删除 suiteXMLfiles 标签,则构建成功

         <suiteXmlFile>AllTestsRelease.xml</suiteXmlFile>

我在这里做错了什么?我需要 suitesXMLFiles 标签来运行测试套件

这里是 AllTestsRelease.xml 文件的代码:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Release Suite">
    <test name="ALL TESTS" parallel="methods" thread-count="5">
        <groups>
           <define name="release">
               <include name="Release"/>
           </define>
           <run>
               <include name="Regression"/>
               <include name="Release"/>
           </run>
       </groups>
       <classes>
            <class name="Search"/>
       </classes>
    </test>
</suite>

【问题讨论】:

【参考方案1】:

尝试提供 AllTestsRelease.xml 文件的完整路径,例如 &lt;suiteXmlFile&gt;src/test/java/testSuites/AllTestsRelease.xml&lt;/suiteXmlFile&gt;

【讨论】:

以上是关于无法编译 TestNG 测试套件(Maven+Surefire)的主要内容,如果未能解决你的问题,请参考以下文章

如何参数化 Maven surefire 插件,以便我可以选择运行哪些 TestNG 套件

从 maven 执行 Testng 套件文件时,它会被忽略,因此不会调用我的侦听器

TestNG套件测试

TestNG.xml 套件包含所有包的所有文件

如何在批处理文件中调用下一个命令之前等待 maven 测试套件完成?

SpringBootTest 和Testng组成测试套件