java - Maven 不运行我的 testng.xml

标签 java maven automation testng

当我运行 testng.xml 时(右键单击 testng.xml,然后以 TestNG 运行),它工作正常 - 我在那里运行的测试中有 2 个正在运行,但是当我从 Maven 运行它时(mvn test)它只执行构建而不运行测试。 顺便说一句 - 我注意到,如果我有包含 Test 一词的类,它们默认在 Maven 上运行,但这对我来说不好,因为我需要能够通过 testng.xml 文件控制测试。

这是我的 pom.xml:

<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>Group1</groupId>
    <artifactId>artifact1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>artifact1</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>




    <profiles>
        <profile>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.20</version>
                        <configuration>
                            <suiteXmlFiles>
                                <suiteXmlFile>testng.xml</suiteXmlFile>
                            </suiteXmlFiles>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>




    <dependencies>

        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.11</version>
        </dependency>



        <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <type>maven-plugin</type>
        </dependency>

    </dependencies>

</project>

这是我的 testng.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite guice-stage="DEVELOPMENT" name="GroupXdefault suite" verbose="0">
    <test name="Default test" verbose ="1">
        <classes>
            <class name="Group1.artifact1.TC1" />
            <class name="Group1.artifact1.TC2" />
        </classes>
    </test> <!-- Default test -->
</suite> <!-- Default suite -->

最佳答案

您可以删除配置文件并尝试使用构建插件

关于java - Maven 不运行我的 testng.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43891582/

相关文章:

java - CopyOnWriteArrayList 可以帮助允许从已放入迭代器的不同线程中删除项目

maven - Jenkins:当 Maven 构建发生在 Docker 容器中时如何使用 JUnit 插件

java - Selenium 检查窗口当前是否打开

c# - C# 中的 Word 自动化语法

java - RxJava 2 在新线程中创建列表

添加新值时,Java ArrayList 值将被重置

java - 如何从服务器获取太大的图像?

未指定 Maven 主目录 - Windows 7 和 IntelliJ

SpringSource 包存储库更改

java - 如何使用 AutoIt 设置 Internet Explorer 选项?