TestNg-09-多线程测试
1、基于注解
package com.course.testng.multiThread;
import org.testng.annotations.Test;
public class ThreadTest {
/**
* invocationCount执行次数
* threadPoolSize 线程池
* 执行3次,线程池为2
*/
@Test(invocationCount = 3,threadPoolSize = 2)
public void test(){
System.out.printf("Thread Id : %s%n",Thread.currentThread().getId());
}
}
4444.png
2、基于xml
package com.course.testng.multiThread;
import org.testng.annotations.Test;
public class ThreadTestXml {
@Test
public void test1(){
System.out.printf("test1 : %s%n",Thread.currentThread().getId());
}
@Test
public void test2(){
System.out.printf("test2 : %s%n",Thread.currentThread().getId());
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<suite name="thread" parallel="classs" thread-count="3">
<!--
parallel
methods 方法级别 ,每一个方法一个线程
classs 类级别 , 每个类一个线程
thread-count:代表了最大并发线程数
-->
<test name = "test0">
<classes name="d">
<class name="com.course.testng.multiThread.ThreadTestXml"/>
</classes>
</test>
<test name = "test1">
<classes name="d1">
<class name="com.course.testng.multiThread.ThreadTestXml"/>
</classes>
</test>
</suite>
网友评论