【问题标题】:Maven Surefire only "default-test" run custom executions ignoredMaven Surefire 仅“默认测试”运行自定义执行被忽略
【发布时间】:2018-07-23 01:37:17
【问题描述】:

我正在使用 maven 3.5.4、maven-surefire-plugin 2.19(我也尝试了 maven-surefire-plugin 2.22 - 结果相同)。 这是我的 POM 的构建部分:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <inherited>true</inherited>
            <configuration>
                <parallel>classes</parallel>
                <threadCount>20</threadCount>
            </configuration>
            <executions>
                <execution>
                    <id>default-test</id>
                    <configuration>
                        <excludedGroups>switch-enabled</excludedGroups>
                    </configuration>
                </execution>
                <execution>
                    <id>other-tests</id>
                    <configuration>
                        <groups>switch-enabled</groups>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我有两组需要单独运行的单元测试(由于静态布尔变量,因此我设置了一个 TestNG 组,并在该组中设置了所有需要打开开关的测试)。

Surefire 仅运行“默认测试”执行并忽略其他执行。我也尝试了以下方法,但也没有用 - 没有运行测试:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <inherited>true</inherited>
            <configuration>
                <parallel>classes</parallel>
                <threadCount>20</threadCount>
            </configuration>
            <executions>
                <execution>
                    <id>default-test</id>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </execution>
                <execution>
                    <id>true-tests</id>
                    <configuration>
                        <groups>switch-enabled</groups>
                    </configuration>
                </execution>
                <execution>
                    <id>false-tests</id>
                    <configuration>
                        <excludedGroups>switch-enabled</excludedGroups>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我做错了什么?

【问题讨论】:

  • 您是否尝试删除default-test 执行?鉴于您无论如何都在跳过它。
  • @dryleaf 是的,然后所有测试都在一次执行中运行,作为默认测试:(

标签: maven testng maven-surefire-plugin


【解决方案1】:

我在使用 surefire 插件时遇到了同样的问题。我建议您将测试运行配置移至 testng .xml 文件,该文件将分别运行每个集合,还可以让您为每个配置并行运行:

    <suite name="Test-Suite">
    <test name="Test first set" parallel="20" preserve-order="true">
        <classes>
            <class name="domain.tests.com.TestA"/>
            <class name="domain.tests.com.TestB"/>
   // Classes of first set here..
        </classes>
    </test>
    <test name="Test second set" parallel="20" preserve-order="true">
        <classes>
            <class name="domain.tests.com.TestC"/>
            <class name="domain.tests.com.TestD"/>
   // Classes of second set here..
        </classes>
    </test>
    </suite>

【讨论】:

  • 我在考虑尝试使用 xml 或使用配置文件作为我最后的手段,是的,它适用于使用 xml :) 非常感谢您的帮助!
【解决方案2】:

我最终使用了@AutomatedOwl 建议的 XML 文件方法。我必须创建一个名为“集成”的新组,我在集成测试类的类级别应用它,因为没有直接的方法来排除 TestNG XML 中的类,我不希望集成测试在万无一失的情况下运行测试阶段。这是我的 TestNG XML:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestAll">
    <test name="falseTest" parallel="classes" thread-count="20">
        <groups>
            <run>
                <exclude name="switch-enabled" />
                <exclude name="integration" />
            </run>
        </groups>
        <packages>
            <package name="com.somecomp" />
        </packages>
    </test>
    <test name="trueTest" parallel="classes" thread-count="20">
        <groups>
            <run>
                <include name="switch-enabled" />
                <exclude name="integration" />
            </run>
        </groups>
        <packages>
            <package name="com.somecomp" />
        </packages>
    </test>
</suite>

这是我的 POM 的构建部分:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <inherited>true</inherited>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 2020-12-31
    • 2021-05-16
    • 2011-04-05
    • 2019-11-20
    相关资源
    最近更新 更多