php红酒网站建设,佛山网站建设公司排行,孕妇做兼职上哪家网站,网站建设挣钱么本文将讨论TestNG中Test annotation的threadPoolSize属性。那么#xff0c;我们开始吧。
那么#xff0c;threadPoolSize属性有什么用处呢#xff1f;答案是#xff0c;无论何时您想要多次并行地运行一个测试方法#xff0c;您都需要这个属性。该方法将从invocationCount…本文将讨论TestNG中Test annotation的threadPoolSize属性。那么我们开始吧。
那么threadPoolSize属性有什么用处呢答案是无论何时您想要多次并行地运行一个测试方法您都需要这个属性。该方法将从invocationCount属性指定的多个线程中调用。
import org.testng.Assert;
import org.testng.annotations.Test;public class CodekruTest {Test(invocationCount 5, threadPoolSize 5)public void testMethod() {int expected 5;int actual 5;Assert.assertEquals(actual, expected);}}
产出-
Executing the test
Executing the test
Executing the test
Executing the test
Executing the test
PASSED: testMethod
PASSED: testMethod
PASSED: testMethod
PASSED: testMethod
PASSED: testMethodDefault testTests run: 5, Failures: 0, Skips: 0
你可能想问invocationCount在那里做什么。如果不使用invocationCount属性我们将无法使用threadPoolSize。
注意如果没有定义invocationCountthreadPoolSize属性将被忽略。
让我们看一个例子。
import org.testng.Assert;
import org.testng.annotations.Test;public class CodekruTest {Test(threadPoolSize 5)public void testMethod() {int expected 5;int actual 5;System.out.println(Executing testMethod);Assert.assertEquals(actual, expected);}}
产出-
Executing testMethod
PASSED: testMethodDefault testTests run: 1, Failures: 0, Skips: 0我们可以看到测试用例只执行了一次。
什么时候可以使用threadPoolSize属性可能有一种情况我们想运行一个测试方法多次比如100次。然后一个接一个地运行100个测试用例可能会花费大量的时间。因此为了减少执行时间我们可以在那里使用一个值比如5的threadPoolSize现在测试用例将在并行实例中运行并且用例将在更短的时间内执行。