Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does TestNG invoke a test method using multiple threads?

Tags:

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

  1. the method will be run a total of 10 times using 3 threads or
  2. 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.

like image 714
Feanor Avatar asked Nov 01 '10 22:11

Feanor


People also ask

How do you run a test method multiple times in TestNG?

By using @Factory and @DataProvider annotation of TestNG you can execute same test-case multiple times with different data.

Is TestNG multithreaded?

The TestNG test automation framework allows you to run tests in parallel or multithreaded mode by utilizing the Multi-Threading concept of Java. Multi-Threading is the process of executing multiple threads simultaneously, without any dependence on each other.


2 Answers

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 :-)

like image 65
Cedric Beust Avatar answered Nov 02 '22 08:11

Cedric Beust


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/

like image 34
chris Avatar answered Nov 02 '22 08:11

chris