testNG multi-threaded test (xml file implementation)

Test cases are generally single-threaded mode, in order to improve test efficiency. Multithreading testNG can be divided into test, class, method-level concurrency, it can set in testng.xml in the suite tag.

methods Level: All use cases are to perform in a different thread.
classs level: may be performed in different threads in different use cases class tag, use cases can only be performed in the same thread in the same class tag.
tests level: may be performed in different threads with different embodiments under test tag, use cases can only be performed in the same thread in the same test tag.

Such as:

<suite name="Testng Parallel Test" parallel="tests" thread-count="3">

<suite name="Testng Parallel Test" parallel="classes" thread-count="3">

<suite name="Testng Parallel Test" parallel="methods" thread-count="3">

 

java code as follows

 1 package com.course.testng.multiThread;
 2 
 3 import org.testng.annotations.Test;
 4 
 5 public class MultiThreadOnXml {
 6 
 7     @Test
 8     public void test1(){
 9         System.out.printf("线程ID"+Thread.currentThread().getId());
10     }
11     @Test
12     public void test2(){
13         System.out.printf("线程ID"+Thread.currentThread().getId());
14     }
15     @Test
16     public void test3(){
17         System.out.printf("线程ID"+Thread.currentThread().getId());
18     }
19 }

xml configuration is as follows

1  <? Xml Version = "1.0" encoding = "UTF-8" ?> 
2  < Suite name = "the Thread" Parallel = "Methods" the Thread-COUNT = "2" > 
3      <-!     Level threads is the method level a
 . 4      Parallel properties
 . 5      Tests Rating: refers test label xml file, typically by name distinguishing may be performed in different threads use cases under different test tag, use cases only one thread at the same test tag for execution in
 6      Methods level: all use cases can go on to perform in a different thread
 7      classs level: perform under the same class tar use cases in the implementation of the same thread in a different class tar use cases in a different thread
 8      the thread -coun property: represents the maximum number of concurrent threads
 9      xml configuration files in this way can not specify the thread pool, the method can only specify the thread pool
 10      ->
11      <test name="demo1">
12         <classes>
13             <class name="com.course.testng.multiThread.MultiThreadOnXml"/>
14         </classes>
15     </test>
16 
17 </suite>

 

 

Guess you like

Origin www.cnblogs.com/linxinmeng/p/12593653.html