TestNG官方网站:
http://testng.org/doc/documentation-main.html
5.10 - Parallelism and time-outs
You can instruct TestNG to run your tests in separate threads in various ways.
5.10.1 - Parallel suites
This is useful if you are running several suite files (e.g. "java org.testng.TestNG testng1.xml testng2.xml") and you want each of these suites to be run in a separate thread. You can use the following command line flag to specify the size of a thread pool:
java org.testng.TestNG |
The corresponding ant task name is suitethreadpoolsize.
5.10.2 - Parallel tests, classes and methods
The parallel attribute on the <suite> tag can take one of following values:
< suite name = "My suite" parallel = "methods" thread-count = "5" >
|
< suite name = "My suite" parallel = "tests" thread-count = "5" >
|
< suite name = "My suite" parallel = "classes" thread-count = "5" >
|
< suite name = "My suite" parallel = "instances" thread-count = "5" >
|
- parallel="methods": TestNG will run all your test methods in separate threads. Dependent methods will also run in separate threads but they will respect the order that you specified.
- parallel="tests": TestNG will run all the methods in the same <test> tag in the same thread, but each <test> tag will be in a separate thread. This allows you to group all your classes that are not thread safe in the same <test> and guarantee they will all run in the same thread while taking advantage of TestNG using as many threads as possible to run your tests.
- parallel="classes": TestNG will run all the methods in the same class in the same thread, but each class will be run in a separate thread.
- parallel="instances": TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will be running in different threads.
Additionally, the attribute thread-count allows you to specify how many threads should be allocated for this execution.
Note: the @Test attribute timeOut works in both parallel and non-parallel mode.
You can also specify that a @Test method should be invoked from different threads. You can use the attribute threadPoolSize to achieve this result:
@Test (threadPoolSize = 3 , invocationCount = 10 , timeOut = 10000 )
|
public void testServer()
|
In this example, the function testServer will be invoked ten times from three different threads. Additionally, a time-out of ten seconds guarantees that none of the threads will block on this thread forever. <!------------------------------------- RERUNNING ------------------------------------>
如果生成数据的方法很复杂,需要重写编写代码实现。可以通过写数据集类,在测试方法中调用测试集数据。
package com.easyway.testng; import org.testng.annotations.DataProvider; /** * 如果生成数据的方法很复杂,需要重写编写代码实现。可以通过写数据集类,在测试方法中调用测试集数据 * * @author longgangbai * 2013-11-19 下午2:43:50 * */ public class DynmicDataProvider { @DataProvider(name = "create") public static Object[][] createData() { return new Object[][] { new Object[] { new Integer(42) } }; } }
package com.easyway.testng; import org.testng.annotations.Test; /** * 制定数据集的类的测试 * @author longgangbai * 2013-11-9 下午2:45:24 * */ @Test public class StaticDataTest { @Test(dataProvider = "create", dataProviderClass = DynmicDataProvider.class,threadPoolSize = 3, invocationCount = 10, timeOut = 10000) public void test(Integer n) { System.out.println(" n ="+n); } }
结果:
[TestNG] Running:
C:\Users\Administrator\AppData\Local\Temp\testng-eclipse--1087250714\testng-customsuite.xml
n =42
PASSED: test(42)
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.XMLReporter@14b84ad: 10 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@114629: 20 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@10a621a: 0 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@4957c7: 0 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@c3dd7e: 0 ms
相关推荐
Learn_TestNG_basicsToAdvanced_RS 测试框架-如何使用TestNG批注和其他属性来控制代码执行流程 使用测试注释运行基本的TestNG... 数据提供者注释-参数化测试用例2 TestNG框架中的侦听器接口 并行运行测试并生成报告
需要大家注册一下免费的企业微信,然后将其中的corpid和通讯录corpsecret填充进testng.xml的参数中,再运行即可测试成功自己的企业微信! Java java当前最主流的替代开发语言,目前做自动化主要是两大阵营java和...
与参数化运行器相比,它的主要优势在于,它可以与任何其他运行器一起使用(例如,如果您正在为 Android 编写测试,则可以与 Robolectric 运行器一起使用)。 博文: ://mikinw.blogspot.co.uk/2013/04/parametrized...
当我们在使用TestNG时,发现它有一个非常好用的参数化功能。当你的测试用例有固定的参数和断言结果时,它可以相似用例的节省用例的个数。 例子如下: import static org.testng.Assert.assertEquals; import org....
TestNg 参数化测试 异常测试 TestNg分组测试和suite文件编写 第 3 章 jTester断言介绍 什么是测试断言? jTester断言基本介绍 jTester断言语法详解 断言String对象 判断字符串是否等于期望值 字符串的模糊判断 ...
Feed4TestNG使得使用从文件(CSV或Excel)导入或生成的数据轻松编写和提供参数化的TestNG测试。
TestNG数据驱动提供的参数化让我们在测试项目可以灵活根据需求建立不同的dataprovider来提供数据,而真正实现数据,页面,测试彼此独立而又有机结合的可能性。 下面这篇文章主要给大家介绍了Java中用enum和testng做...
参数化(多环境支持) 对象对比、两个Json对比 指定需要运行的case(冒烟,回归,全量等。。。) 详细的测试报告,可以回溯每个case的历史执行记录,并报告展示每个请求请求 支持任意次数的失败重跑 支持多种并发...
使用Excel驱动的数据在JUnit中编写TestNG样式的参数化测试
5.3.6 参数化定制类型 5.3.7 映射枚举 5.4 小结 第6章 映射集合和实体关联 6.1 值类型的set、bag、list和map 6.1.1 选择集合接口 6.1.2 映射set 6.1.3 映射标识符bag 6.1.4 映射...
测试数据与代码分离,使用excel中的APACHE poi仅通过其测试用例名称导入,并将其作为参数传递给数据提供者注释,后者将其传递到测试用例。 输出 报告是生成的指示故障,并通过两个分区文件的Separte文件夹中的Extent...
Selenium Java Framework是使用Java,Selenium和Zalenium编写CI自动运行测试的UI自动化测试的良好起点。 产品特点 多个域 可以将测试配置为针对不同的域运行。 例如: : 和 。 多种环境 与针对多个域的测试类似,...
13.1 用JUnit and TestNG创建测试 504 13.1.1 问题 504 13.1.2 解决方案 504 13.1.3 工作原理 504 13.2 创建单元测试和集成测试 509 13.2.1 问题 509 13.2.2 解决方案 509 13.2.3 工作原理 510 13.3...
13.1 用JUnit and TestNG创建测试 504 13.1.1 问题 504 13.1.2 解决方案 504 13.1.3 工作原理 504 13.2 创建单元测试和集成测试 509 13.2.1 问题 509 13.2.2 解决方案 509 13.2.3 工作原理 510 13.3...