TestNG 八 并发测试
来源:互联网 发布:北京公交卡充值软件 编辑:程序博客网 时间:2024/04/18 18:39
一、 Concurrenttesting:
下面的例子是输出进程ID,threadPoolSize用来指明线程池的大小,也就是并发的线程数目是多少
5次调用,有3个线程可调用
@Test(invocationCount = 5, threadPoolSize = 3,groups = { "t9"})public void smallThreadPool() {System.out.println("Thread#: " +Thread.currentThread().getId());}
页面输出
[TestNG]Running:
E:\android\selenium\test_wdng_java\src\testing.xml
Thread#:13
Thread#:15
Thread#: 14
Thread#:15
Thread#:15
===============================================
Suite
Totaltests run: 5, Failures: 0, Skips: 0
===============================================
若改成5次调用,有5个线程可调用
Thread#:10
Thread#:14
Thread#:12
Thread#:11
Thread#:13
二、Concurrentrunning of tests
TestNG可以以多线程的模式运行所有的test,这样可以获得最大的运行速度,最大限度的节约执行时间。当然,并发运行也是有代价的,就是需要我们的代码是线程安全的。
并发运行测试的话,需要我们指定运行的配置文件,一个示例如下:
<suite name="Concurrent Suite" parallel="methods" thread-count="2" verbose="1" ><>……<></suite>
1.Parallel=”methods”的意思是指TestNG会将method作为并发的元子单位,即每个method运行在自己的thread中。如果parallel=”tests”,则指会将test 作为并发的元子单位
2.Thread-count=”2”是指,运行的时候,并发度为2,同时会有两个线程在运行。
例如:
@Test(groups = { "t8"})public void aThreadPool() {System.out.println("#ThreadA: " +Thread.currentThread().getId());}@Test(groups = { "t8"})public void bThreadPool() {System.out.println("#ThreadB: " +Thread.currentThread().getId());}@Test(groups = { "t8"})public void cThreadPool() {System.out.println("#ThreadC: " +Thread.currentThread().getId());}
--------------------------------------------------------------------
<testname="Test" parallel="methods"thread-count="2">
输出结果:
#ThreadB:11
#ThreadC:11
#ThreadA:10
===============================================
Suite
Totaltests run: 3, Failures: 0, Skips: 0
===============================================
改成<testname="Test" parallel="tests" thread-count="2">
页面输出(因为aThreadPool(),bThreadPool(),cThreadPool()都在一个test下面)
#ThreadA:1
#ThreadB:1
#ThreadC:1
===============================================
Suite
Totaltests run: 3, Failures: 0, Skips: 0
===============================================
本文转载自http://blog.sina.com.cn/bestfeiyong- TestNG 八 并发测试
- TestNG·八 并发测试
- Testng并发测试
- TestNG 学习总结 - 忽略测试(八)
- TestNG并发兼容性测试testng.xml文件的配置
- 使用testNG进行并发性能测试
- 使用testNG进行并发性能测试
- TestNG测试的并发执行详解
- 用testNG测试,可以做简单的并发测试
- testNG测试配置文件testng.xml
- testNG进行并发编程
- TestNG 并发参数一览
- selenium+testng+gitblit+jenkins+ant自动化测试系列八:ant安装
- 结合selenium grid和testNG实现自动web测试的并发执行
- 结合selenium grid和testNG实现自动web测试的并发执行
- 结合selenium grid和testNG实现自动web测试的并发执行
- Java + TestNG + Appium 实现单机多个Android终端并发测试
- TestNG系列-第五章 测试方法、测试类和测试分组(续5)-9类级别注解、并发、失败情况
- Android控件之ListView
- 一些测试总结
- Poco中的RunnableAdaptor实现浅析
- 用Detours实现APIHOOK
- How to Get Virtual Desktops on Windows with Dexpot
- TestNG 八 并发测试
- C# Socket TCP 协议接收器
- 记录--嵌套类和局部类
- poj 1426 Find The Multiple (bfs+同余定理)
- paip.从HTML select 获取数据
- android meta-data
- nfs挂载文件系统
- 哈佛为什么群星闪耀?
- JavaScript 创建类/对象的几种方式