TestNG 并发参数一览

来源:互联网 发布:不愉快的怪物庵 知乎 编辑:程序博客网 时间:2024/05/01 12:05

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命令行参数

有三个参数,如下所示

Option Argument Documentation -dataproviderthreadcount The 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. -parallel methods tests -threadcount The 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配置文件中的值覆盖。

1 0
原创粉丝点击