【问题标题】:How to run testng.xml from Maven?如何从 Maven 运行 testng.xml?
【发布时间】:2017-05-09 20:34:22
【问题描述】:

我在 pom.xml 文件上配置了我的 testng1.xml,但它看起来仍然只是运行所有具有 @Test 注释的测试,而不是仅运行那些在 testng1.xml 文件中配置的测试。 我从谷歌复制了很多例子,但没有任何效果。

请帮忙。

这是我的 testng1.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">
  <test verbose="2" name="Default test">
    <classes>
        <class name="GroupX.ArtifactX.Test2"/>
        <class name="GroupX.ArtifactX.Test3"/>
    </classes>
  </test> <!-- Default test -->
</suite> <!-- Default suite -->

这是我的 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>GroupX</groupId>
  <artifactId>ArtifactX</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>ArtifactX</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>testng1.xml</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

  <dependencies>

    <!-- 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>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.11</version>
    </dependency>



  </dependencies>
</project>

【问题讨论】:

标签: maven testng


【解决方案1】:

您的配置文件配置错误(缺少 ID 且配置文件未激活)。只需移动&lt;project&gt; 中的&lt;build&gt; 部分即可。

【讨论】:

    【解决方案2】:

    尝试包含如下代码所示的 testng.xml 路径

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <inherited>true</inherited>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    

    【讨论】:

      猜你喜欢
      • 2017-08-08
      • 2017-10-09
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2017-06-01
      • 2020-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多