【问题标题】:Maven failsafe. How to execute only the suite file and not standalone tests?Maven 故障保护。如何仅执行套件文件而不执行独立测试?
【发布时间】:2018-02-08 12:42:23
【问题描述】:

我有一个为整个项目运行集成测试的子模块,它有几个模块。这是集成测试子模块 pom:

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.sample.server</groupId>
        <artifactId>jacoco-test</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>com.sample.server.modules</groupId>
    <artifactId>integration_test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>integration_test</name>
    <url>http://maven.apache.org</url>

    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.4</version>
        </dependency>
        <dependency>
            <groupId>com.sample.server.modules</groupId>
            <artifactId>api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.20.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <suiteXmlFiles>
                                <suiteXmlFile>${project.basedir}/testng/api.xml</suiteXmlFile>
                            </suiteXmlFiles>
                        </configuration>
                    </execution>
                </executions>

            </plugin>
</project>

当我执行 mvn install 或 verify 时,所有独立测试都会运行,之后 xml 套件也会运行。

我只想运行套件文件,我需要这样做,因为套件之外的某些测试失败。 我尝试使用排除选项,但故障安全忽略了该选项。

我该怎么做?

【问题讨论】:

    标签: java maven maven-failsafe-plugin


    【解决方案1】:

    把 pom.xml 改成

     <configuration>
    
     <excludes>
                <exclude>**/TestCircle.java</exclude>
                <exclude>**/TestSquare.java</exclude>
              </excludes>
     <suiteXmlFiles>
                                    <suiteXmlFile>${project.basedir}/testng/api.xml</suiteXmlFile>
     </suiteXmlFiles>
    </configuration>
    

    排除项是您不想运行的测试。

    【讨论】:

    • 但这也跳过了 xml 套件
    • 不,不,你还没明白我的问题是什么。我不想跳过或排除测试,我想执行那些测试,但是从 xml 文件。现在故障安全正在独立执行测试和 xml 文件,我只想执行 xml 文件。
    • 我发现了问题。是独立执行测试的父 pom。因此,解决方案是在父级别跳过测试并在子模块中重新启用它。我认可你的回答,因为你给我指明了方向
    猜你喜欢
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 2018-03-07
    • 2013-11-12
    相关资源
    最近更新 更多