java UI自动化 使用命令mvn clean test构建测试用例 报错[ERROR] There are test failures.

想请教下 执行 mvn clean test 命令构建测试 报错 There are test failures. 一个用例都没有成功 是什么原因呢



直接运行 这个测试类 是可以的


下面是我的pom配置

<?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>autotest-console-todesk-c</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- TestNG依赖导入https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version>
            <scope>test</scope>
        </dependency>

        <!-- Junit5相关依赖导入-->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-runner</artifactId>
            <version>1.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-launcher</artifactId>
            <version>1.7.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-console-standalone</artifactId>
            <version>1.7.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-engine</artifactId>
            <version>1.7.0</version>
        </dependency>

        <!-- Selenium用到的pom依赖-->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <!--日志组件依赖-->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>


        <!--allure报表依赖-->
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-testng</artifactId>
            <version>2.13.2</version>
            <scope>test</scope>
        </dependency>

    </dependencies>


    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>

        <!--在pom.xml文件中的<project>标签下设置属性,避免乱码-->
        <aspectj.version>1.8.10</aspectj.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>

    </properties>

    <!-- <project>标签下引入Maven Surefire插件:生成Allure报表-->
    <build>
        <plugins>
            <plugin>
                <!-- maven-surefire-plugin 配合testng执行测试用例的maven插件 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <!-- 测试失败后,是否忽略并继续测试 -->
                    <testFailureIgnore>true</testFailureIgnore>
                    <suiteXmlFiles>
                        <!-- testng配置文件名称 -->
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <!--设置参数命令行 -->
                    <argLine>
                        <!-- UTF-8编码 -->
                        -Dfile.encoding=UTF-8
                        <!-- 配置拦截器 -->
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                    <systemProperties>
                        <property>
                            <!-- 配置 allure 结果存储路径 -->
                            <name>allure.results.directory</name>
                            <value>${project.build.directory}/allure-results</value>
                        </property>
                    </systemProperties>
                </configuration>
                <dependencies>
                    <!-- aspectjweaver maven坐标 -->
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

用的是同一个pom文件吗 可能命令行和idea不是同一个

是的 就是我上面帖子 附上的pom文件

我去掉下面的pop配置(生成allure报表的配置),执行mvn clean test 命令 可以正常实行到测试用例

应该是下面的依赖有问题,老师可以帮我看看吗?

<build>
    <plugins>
        <plugin>
            <!-- maven-surefire-plugin 配合testng执行测试用例的maven插件 -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.1</version>
            <configuration>
                <!-- 测试失败后,是否忽略并继续测试 -->
                <testFailureIgnore>true</testFailureIgnore>
                <suiteXmlFiles>
                    <!-- testng配置文件名称 -->
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
                <!--设置参数命令行 -->
                <argLine>
                    <!-- UTF-8编码 -->
                    -Dfile.encoding=UTF-8
                    <!-- 配置拦截器 -->
                    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                </argLine>
                <systemProperties>
                    <property>
                        <!-- 配置 allure 结果存储路径 -->
                        <name>allure.results.directory</name>
                        <value>${project.build.directory}/allure-results</value>
                    </property>
                </systemProperties>
            </configuration>
            <dependencies>
                <!-- aspectjweaver maven坐标 -->
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjweaver</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>8</source>
                <target>8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

项目地址发过来看看吧

麻烦老师 帮忙看看哈

<?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>autotest-console-todesk-c</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- TestNG依赖导入https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>5.2</version>
        </dependency>
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-testng</artifactId>
            <version>2.13.6</version>
        </dependency>


        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.8</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
            <version>2.9.9</version>
        </dependency>

        <!-- Selenium用到的pom依赖-->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>7.5.1</version>
        </dependency>

        <!--        <dependency>-->
        <!--            <groupId>com.github.appium</groupId>-->
        <!--            <artifactId>java-client</artifactId>-->
        <!--            <version>7.5.1</version>-->
        <!--        </dependency>-->

        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock-jre8</artifactId>
            <version>2.28.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>net.lightbody.bmp</groupId>
            <artifactId>browsermob-core</artifactId>
            <version>2.1.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.github.spullara.mustache.java</groupId>
            <artifactId>compiler</artifactId>
            <version>0.9.10</version>
        </dependency>

        <!--日志组件依赖-->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

    </dependencies>
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>

        <!--在pom.xml文件中的<project>标签下设置属性,避免乱码-->
        <aspectj.version>1.8.10</aspectj.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>

    </properties>

    <!--在<project>标签下引入Maven Surefire插件:生成Allure报表-->
<!--    <build>-->
<!--        <plugins>-->
<!--            <plugin>-->
<!--                &lt;!&ndash; maven-surefire-plugin 配合testng执行测试用例的maven插件 &ndash;&gt;-->
<!--                <groupId>org.apache.maven.plugins</groupId>-->
<!--                <artifactId>maven-surefire-plugin</artifactId>-->
<!--                <version>2.22.1</version>-->
<!--                <configuration>-->
<!--                    &lt;!&ndash; 测试失败后,是否忽略并继续测试 &ndash;&gt;-->
<!--                    <testFailureIgnore>true</testFailureIgnore>-->
<!--                    <suiteXmlFiles>-->
<!--                        &lt;!&ndash; testng配置文件名称 &ndash;&gt;-->
<!--                        <suiteXmlFile>testng.xml</suiteXmlFile>-->
<!--                    </suiteXmlFiles>-->
<!--                    &lt;!&ndash;设置参数命令行 &ndash;&gt;-->
<!--                    <argLine>-->
<!--                        &lt;!&ndash; UTF-8编码 &ndash;&gt;-->
<!--                        -Dfile.encoding=UTF-8-->
<!--                        &lt;!&ndash; 配置拦截器 &ndash;&gt;-->
<!--                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"-->
<!--                    </argLine>-->
<!--                    <systemProperties>-->
<!--                        <property>-->
<!--                            &lt;!&ndash; 配置 allure 结果存储路径 &ndash;&gt;-->
<!--                            <name>allure.results.directory</name>-->
<!--                            <value>${project.build.directory}/allure-results</value>-->
<!--                        </property>-->
<!--                    </systemProperties>-->
<!--                </configuration>-->
<!--                <dependencies>-->
<!--                    &lt;!&ndash; aspectjweaver maven坐标 &ndash;&gt;-->
<!--                    <dependency>-->
<!--                        <groupId>org.aspectj</groupId>-->
<!--                        <artifactId>aspectjweaver</artifactId>-->
<!--                        <version>${aspectj.version}</version>-->
<!--                    </dependency>-->
<!--                </dependencies>-->
<!--            </plugin>-->
<!--            <plugin>-->
<!--                <groupId>org.apache.maven.plugins</groupId>-->
<!--                <artifactId>maven-compiler-plugin</artifactId>-->
<!--                <configuration>-->
<!--                    <source>8</source>-->
<!--                    <target>8</target>-->
<!--                </configuration>-->
<!--            </plugin>-->
<!--        </plugins>-->
<!--    </build>-->

</project>

你的项目是testng的测试框架,不要用junit5的依赖,一个项目只用一个测试框架的依赖


我用了你上面的配置文件,我把报表的依赖配置上后,

我执行mvn clean test这边还是报这个错 :no_mouth:

<?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>autotest-console-todesk-c</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- TestNG依赖导入https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>5.2</version>
        </dependency>
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-testng</artifactId>
            <version>2.13.6</version>
        </dependency>


        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.8</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
            <version>2.9.9</version>
        </dependency>

        <!-- Selenium用到的pom依赖-->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>7.5.1</version>
        </dependency>

        <!--        <dependency>-->
        <!--            <groupId>com.github.appium</groupId>-->
        <!--            <artifactId>java-client</artifactId>-->
        <!--            <version>7.5.1</version>-->
        <!--        </dependency>-->

        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock-jre8</artifactId>
            <version>2.28.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>net.lightbody.bmp</groupId>
            <artifactId>browsermob-core</artifactId>
            <version>2.1.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.github.spullara.mustache.java</groupId>
            <artifactId>compiler</artifactId>
            <version>0.9.10</version>
        </dependency>

        <!--日志组件依赖-->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

    </dependencies>
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>

        <!--在pom.xml文件中的<project>标签下设置属性,避免乱码-->
        <aspectj.version>1.8.10</aspectj.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>

    </properties>

<!--    在<project>标签下引入Maven Surefire插件:生成Allure报表-->
        <build>
            <plugins>
                <plugin>
                    <!-- maven-surefire-plugin 配合testng执行测试用例的maven插件 -->
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                    <configuration>
                        <!-- 测试失败后,是否忽略并继续测试 -->
                        <testFailureIgnore>true</testFailureIgnore>
                        <suiteXmlFiles>
                            <!-- testng配置文件名称 -->
                            <suiteXmlFile>testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
                        <!--设置参数命令行 -->
                        <argLine>
                            <!-- UTF-8编码 -->
                            -Dfile.encoding=UTF-8
                            <!-- 配置拦截器 -->
                            -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                        </argLine>
                        <systemProperties>
                            <property>
                                <!-- 配置 allure 结果存储路径 -->
                                <name>allure.results.directory</name>
                                <value>${project.build.directory}/allure-results</value>
                            </property>
                        </systemProperties>
                    </configuration>
                    <dependencies>
                        <!-- aspectjweaver maven坐标 -->
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjweaver</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>8</source>
                        <target>8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>

</project>


这个项目中没有配置文件呀

老师 我问题解决了,谢谢老师。 :smile:是因为新版本的testng.xml 增加了dtd协议判断,所以我一下的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite" parallel="tests" thread-count="2">
    <test name="测试">
        <classes>
            <class name="todesk.testcases.TestLogin"/>
        </classes>
    </test>
</suite>

修改为https协议,就好了