Testng中的并行化类和方法 [英] Parallelizing classes and method in testng

查看:98
本文介绍了Testng中的并行化类和方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用例,必须在一个类下动态运行某些测试方法.

I have a usecase where I have to run certain test methods under one class dynamically.

我正在使用@factory批注动态生成这些测试类.

I am using @factory annotation for generating these test classes dynamically.

我已经在上述类下并行运行了我的测试方法.

I already have my test methods under the mentioned class running in parallel.

如何使测试类和测试方法并行?反正还有吗?

How do I make the test classes and test methods both parallel? Is there anyway to do it as well?

public class FactoryClass {

    @Factory
    public Object[] factoryMethod() {
        return new Object[] { new TestClass(), new TestClass() }
    }
}

public class TestClass {

    @DataProvider(name = "firstDataProvider", parallel = true)
    public Object[] firstDataProvider() {
        return new Object[] { };
    }

    @DataProvider(name = "secondDataProvider", parallel = true)
    public Object[] secondDataProvider() {
        return new Object[] { };
    }

    @Test(dataProvider = "firstDataProvider")
    public void firstTestMethod(String arg) {

    }

    @Test(dataProvider = "secondDataProvider")
    public void secondTestMethod(String arg) {

    }
}

test.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1" parallel="methods"  data-provider-thread-count="60">
    <test name="test1">
        <classes>
            <class name="com.amriteya.test.FactoryMain"></class>     
        </classes>
    </test>
</suite>

以下是我的课堂布局.

Following is the layout of my classes.

test.xml中,我正在设置parallel ="methods",但它没有为我提供正确的输出.

In test.xml I am setting parallel="methods" but it is not providing the right output for me.

推荐答案

不能同时为测试方法和测试类设置并行属性.看来您需要在套件级别设置并行测试,并在测试级别设置并行类/方法,这里的testng xml示例很清楚:

You can't set parallel property to both test method and test class. It seems that you need to set parallel tests on a suite level and parallel classes/methods on a test level, here example of testng xml to be clear:

<suite name="Suite1" parallel="tests">
    <test name="test1" parallel="methods">
        <classes>
            <class name="FactoryClass"/>
        </classes>
    </test>
    <test name="test2" parallel="methods">
        <classes>
            <class name="FactoryClass"/>
        </classes>
    </test>
</suite>

所有方法将在唯一线程中运行. 当您要在多个浏览器组上并行运行测试时,这种情况很有用.套件级别的并行选项将定义您具有两个浏览器池(Chrome和Firefox-并将适当的参数传递给测试),而测试级别的parellel选项将定义池中有多少个浏览器.

All methods will run in unique thread. This case is useful when you want to run tests in parallel for example on several groups of browsers. Parallel option on suite level will define that you have e.g. two pools of browsers (Chrome and Firefox - and you will pass appropriate params to tests), and parellel option on test level will define how many browsers do you have in the pool.

这篇关于Testng中的并行化类和方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆