通过注解
import org.testng.annotations.Test;
public class MultiThreadTest {
//invocationCount 用10个线程执行;threadPoolSize 线程池
//如果不设线程池Size,则还是只会用1个线程挨着执行
@Test(invocationCount = 10,threadPoolSize = 3)
public void test(){
System.out.println(1);
System.out.printf("Thread id : %s%n",Thread.currentThread().getId());
}
}
执行结果:
共执行10次,用三个线程交替执行。
1
Thread id : 11
1
Thread id : 13
1
Thread id : 12
1
Thread id : 12
1
Thread id : 13
1
Thread id : 11
1
Thread id : 13
1
Thread id : 13
1
Thread id : 12
1
Thread id : 11
===============================================
Default Suite
Total tests run: 10, Passes: 10, Failures: 0, Skips: 0
==