【问题标题】:Run testng tests from parent pom从父 pom 运行 testng 测试
【发布时间】:2017-04-23 14:57:07
【问题描述】:

我正在尝试从父 pom 运行 TestNG Selenium 测试。当我运行命令 mvn install BUILD SUCCESSFUL 时,会显示消息,但未运行测试。

以下是我的文件夹结构:

Parent
|----Child1
|      |---src
|      |---pom.xml
|----Child2
|      |---src
|      |---pom.xml
|      |---myTests.xml
|-pom.xml

当命令 mvn install 从 Child2 文件夹运行且没有任何更改时,将运行测试。

父 pom.xml 文件如下所示:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.parent</groupId>
    <artifactId>parent</artifactId>
    <version>1</version>
    <packaging>pom</packaging>
    <profiles>
        <profile>
            <modules>
                <module>Child1</module>
                <module>Child2</module>
            </modules>
        </profile>
    </profiles>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.15</version>
                <configuration>
                    <skipTests>false</skipTests>
                    <suiteXmlFiles>
                        <suiteXmlFile>myTests.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

孩子1 - pom.xml

<parent>
    <groupId>com.example.parent<groupId>
    <artifactId>parent</artifactId>
    <version>1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.parent</groupId>
<artifactId>Child1</artifactId>
<version>1</version>

孩子2 - pom.xml。该项目依赖于 Child1

<parent>
    <groupId>com.example.parent</groupId>
    <artifactId>parent</artifactId>
    <version>1</version>
</parent>
<groupId>com.example.parent</groupId>
<artifactId>Child2</artifactId>
<version>1</version>
<dependencies>
    <dependency>
        <groupId>com.example.parent</groupId>
        <artifactId>Child1</artifactId>
        <version>1</version>
    </dependency>
</dependencies>

【问题讨论】:

  • myTests.xml 不指向 myTests.xml,因为 myTests.xml 位于不同的目录中。尝试将其更改为 Child2/myTests.xml
  • 我用代码块替换了您的内联代码标记 (`)。在 SO 上格式化代码块的最简单方法是粘贴代码,然后选择它并按 Ctrl+K 或单击 {} 按钮。这会将整个块缩进另外四个空格,指示 Stack Overflow 将其格式化为代码。
  • @mackowski:我已经尝试给出你提到的相对路径Child2/myTests.xml,但没有抛出错误。我假设如果maven找不到指定的路径,那么它会抛出错误。

标签: maven selenium testng pom.xml parent-pom


【解决方案1】:

我在父 pom 的插件下添加了以下代码,并为我运行了测试。

<plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin>

【讨论】:

    猜你喜欢
    • 2012-09-23
    • 1970-01-01
    • 2019-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多