multithreading TestNG 如何使用多线程调用测试方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4073708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does TestNG invoke a test method using multiple threads?
提问by Feanor
In the TestNG documentation, there is a section describing how to tell TestNG to invoke test methods using multiple threads:
在 TestNG 文档中,有一节描述了如何告诉 TestNG 使用多个线程调用测试方法:
You can also specify that a @Test method should be invoked from different threads. You can use the attribute threadPoolSize to achieve this result:
您还可以指定应从不同线程调用 @Test 方法。您可以使用属性 threadPoolSize 来实现此结果:
@Test(threadPoolSize = 3, invocationCount = 10, timeOut = 10000)
public void testServer() {
In this example, the function testServer will be invoked ten times from three different threads.(emphasis mine)
在这个例子中,函数 testServer 将从三个不同的线程调用十次。(强调我的)
My question is whether the text above means that
我的问题是上面的文字是否意味着
- the method will be run a total of 10 times using 3 threads or
- the method will be run a total of 30 times, with 3 threads running the method 10 times each.
- 该方法将使用 3 个线程总共运行 10 次或
- 该方法将总共运行 30 次,其中 3 个线程每个运行该方法 10 次。
My thought is that because the invocation count is associated with the method, 1 is the correct interpretation, but I would appreciate being corrected if I'm wrong.
我的想法是,因为调用计数与方法相关联,所以 1 是正确的解释,但如果我错了,我希望得到纠正。
回答by Cedric Beust
Yes, 1 is the correct answer.
是的,1是正确答案。
As a side note, writing a quick test case to verify this hypothesis would probably have been faster than writing up the question :-)
作为旁注,编写一个快速测试用例来验证这个假设可能比编写问题要快:-)
回答by chris
Use @Test(threadPoolSize = 3, invocationCount = 10, timeOut = 10000) , which run asynchronous tests in multiple threads.
使用 @Test(threadPoolSize = 3, invocationCount = 10, timeOut = 10000) ,它在多个线程中运行异步测试。
you may take a look: http://www.asjava.com/testng/testng-tutorial-time-test-with-annotation-timeout/
你可以看看:http: //www.asjava.com/testng/testng-tutorial-time-test-with-annotation-timeout/