TestNG 如何使用多线程调用测试方法?
在 TestNG 文档中,有一节描述了如何告诉 TestNG 使用多个线程调用测试方法:
您还可以指定 @Test 方法应该从调用 不同的线程。您可以使用 属性threadPoolSize来实现 这个结果:
@Test(threadPoolSize = 3, invocationCount = 10, timeOut = 10000)
public void testServer() {
在此示例中,函数 testServer 将被调用十次 来自三个不同的线程。(强调我的)
我的问题是上面的文本是否意味着
- 该方法将总共运行 使用 3 个线程运行 10 次或
- 该方法将总共运行 30 次,其中 3 个线程各运行该方法 10 次。
我的想法是,因为调用计数与方法相关联,所以 1 是正确的解释,但如果我错了,我将不胜感激。
In the TestNG documentation, there is a section describing how to tell TestNG to invoke test methods using multiple threads:
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 = 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)
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,1 是正确答案。
作为旁注,编写一个快速测试用例来验证这个假设可能比写下问题更快:-)
Yes, 1 is the correct answer.
As a side note, writing a quick test case to verify this hypothesis would probably have been faster than writing up the question :-)
使用 @Test(threadPoolSize = 3, invokingCount = 10, timeOut = 10000) ,它在多个线程中运行异步测试。
你可以看一下: http://www. asjava.com/testng/testng-tutorial-time-test-with-annotation-timeout/
Use @Test(threadPoolSize = 3, invocationCount = 10, timeOut = 10000) , which run asynchronous tests in multiple threads.
you may take a look: http://www.asjava.com/testng/testng-tutorial-time-test-with-annotation-timeout/