TestNG 并发参数一览

本文详细梳理了TestNG并发测试的各项参数,包括在testng.xml配置文件中的suite、test和class标签级别的`parallel`, `thread-count`, `data-provider-thread-count`等参数,以及源代码中@Test和@DataProvider注解的并发相关参数。通过这些参数,可以灵活控制并发的粒度、线程数量,实现高效的并发测试。" 112096078,10536973,SpringBoot整合Hessian远程调用详解,"['SpringBoot', 'Hessian', '远程调用框架', 'Binary RPC', '服务发布']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

TestNG支持多种方式的并发测试,官方文档并没有对所有的参数进行系统说明,本文对TestNG并发参数进行梳理,以期对TestNG并发测试功能获得全面的认识。

testng.xml配置文件中的参数

suite tag级别参数

parallel (false | methods | tests | classes | instances) “false”
thread-count CDATA “5”
data-provider-thread-count CDATA “10”

  1. parallel
    在suite tag级别指定TestNG并发的粒度,支持false,methods,tests,classes,instances。默认是false不并发。
  2. thread-count
    并发的线程数,默认是5个线程。
  3. data-provider-thread-count
    指定以DataProvider传入参数的测试方法的并发线程数,默认是10个。

test tag级别参数

parallel CDATA #IMPLIED
thread-count CDATA #IMPLIED

  1. parallel
    在test tag级别指定并发的级别,与suite tag级别的取值范围一样,如果指定覆盖suite tag级别的参数值。
  2. thread-count
    在test tag级别指定并发的线程数,与suite tag级别的取值范围一样,如果指定覆盖suite tag级别的取值。

class tag级别

源代码中指定的参数

@Test annotation的参数

threadPoolSize
invocationCount

这两个@Test annotation的参数是在一起使用的,可以指定某个测试方法的并发数和总运行次数。
1. threadPoolSize
测试方法并发线程池的大小,也是并发线程的个数。
2. invocationCount
总调用次数,会以threadPoolSize指定的线程数并发运行invocationCount次。

@DataProvider annocation的参数

parallel (true|false)

  1. parallel
    如果指定为true,DataProvider中的数据会以并发的方式读取,并驱动相应测试方法并发执行。

TestNG命令行参数

有三个参数,如下所示

OptionArgumentDocumentation
-dataproviderthreadcountThe default number of threads to use for data providers when running tests in parallel.This sets the default maximum number of threads to use for data providers when running tests in parallel. It will only take effect if the parallel mode has been selected (for example, with the -parallel option). This can be overridden in the suite definition.
-parallelmethodstests
-threadcountThe default number of threads to use when running tests in parallel.This sets the default maximum number of threads to use for running tests in parallel. It will only take effect if the parallel mode has been selected (for example, with the -parallel option). This can be overridden in the suite definition.

基本上就是suite tag级别参数的命令行形式,会被testng.xml配置文件中的值覆盖。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值