java - 并行运行testNG套件

标签 java testing gradle automated-tests testng

我用gradle + testNG

测试动态生成集合XML文件

结果,有一个文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="2" name="Suite" parallel="instances">
    <suite-files>
        <suite-file path="test-suite.xml"/>
        <suite-file path="test2-suite.xml"/>
    </suite-files>
</suite>

如何开始并行执行数据套件?

该文档有一个使用maven和-suitethpoolsize的示例

https://testng.org/doc/documentation-main.html#parallel-suites

不适合gradle

我搜索了互联网,但找不到可行的解决方案

最佳答案

您可以考虑为此使用自定义运行器。创建一个新的测试类,然后创建一个TestNG实例,并将其提供给您的套件,例如:

class TestExecutor {
    @Test
    public runTests() {
         List<String> suites = ... // Set here your xml paths

         TestNG testNg = new TestNG();
         testNg.setSuiteThreadPoolSize(suites.size());
         testNg.setTestSuites(suites);
         // you may also register your listeners here, e.g.:
         // testNg.addListener(new MyITestListener());
         testNg.run();
    }
}

最后,在您的gradle.build文件中包括唯一的测试类:
test {
    useTestNG() {
    }
    include("**/TestExecutor.class")
}

现在Gradle将运行您的单个测试,这将并行触发所有测试套件。

关于java - 并行运行testNG套件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61793398/

相关文章:

android - 激活 proguard 时 Gradle 构建失败

java - 使用 Java 在 Eclipse 中编辑一些首选项

testing - 如何找到用于 cargo 测试的资源?

python - 如果 setUp 在 Python unittest 中引发异常,则停止运行测试

ruby-on-rails - 当我重命名列时,如何确保我的 View 没有在我的测试套件中使用旧名称引用该列?

android - 测试运行失败 : Unable to find instrumentation info for: ComponentInfo{} -- error trying to test in IntelliJ with Gradle

java - 尝试与父类中的对象共享套接字

java - Web 应用程序 Controller 中的参数映射大小验证与 Web 安全有什么好处

java - 使用找到的模式从 Java 正则表达式匹配器获取 NULL 值

java - gradle编译成功,但项目运行失败