首页 > 解决方案 > TestNG 中的 setTestClasses 不适用于 setParallel?

问题描述

所以我想让我的 testNG 类并行运行。我还使用这样的工厂生成这些 testNG 类:

    @Factory
    public Object[] makeTests() {
        Object[] tests = new Object[2];
        for (int i = 0; i < 2; i++) {
            tests[i] = new SampleTestClass(i);
        }
        return tests;
    }

    public static void main(String[] args) {
        TestNG tng = new TestNG();

        tng.setTestClasses(new Class[] {TestEngine.class});
        tng.run();

    }

我想并行运行这些测试类。但是当我尝试使用 tng.setParallel(XmlSuite.ParallelMode.CLASSES) 时,它不起作用。当我指定时,maven surefire 插件也没有:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <configuration>
                    <parallel>classes</parallel>
                    <threadCount>10</threadCount>
                </configuration>
            </plugin>
        </plugins>
    </build>

这种设置测试类的方式是否有不同的并行化方式?

编辑:找到解决方案,它应该是 ParallelMode.INSTANCES。

标签: javamaventestngmaven-surefire-plugin

解决方案


我对 Maven Surefire 也有类似的问题。唯一适用于并行执行的是:

<property>
    <name>suitethreadpoolsize</name>
    <value>16</value>
</property>

属性,maven-surefire 属性的一部分。


推荐阅读