如果冒烟测试失败则停止测试执行

问题描述

我有 2 个名为 testng_smoke.xml 和 testng_regression.xml 的 testng.xml 文件。我已经将 pom.xml 配置如下以运行这些 testng 文件

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>src/test/resources/testng_smoke.xml</suiteXmlFile>
                    <suiteXmlFile>src/test/resources/testng_regression.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>

在这里它执行两个 testng 文件并在最后给出构建的状态(成功或失败)。

但我的要求是首先运行冒烟测试套件 (testng_smoke.xml),如果冒烟测试套件中存在任何测试失败,则构建失败,而不移动到回归测试套件 (testng_regression.xml)。有没有可能达到这个要求。

解决方法

AFAIK,在测试中没有开箱即用的方式来做到这一点。

如果您正在使用 Jenkins 或某些 CI,那么最好创建两个作业或管道,以便第二个任务依赖于第一个任务的结果。

如果不是,并且您想使用单个文件,那么可能的解决方案之一可能是将变量作为文件或环境变量来维护,其值可以在suiteListener afterSuite 方法中设置。然后 beforeSuite 方法可以抛出 SkipException 以忽略基于变量值的套件。