Thursday 12 March 2020

TestNG: Run independent test method in parallel

In my previous post, I explained how to run a test method ‘n’ number of times by setting invocationCount property. You can even run the test method in parallel by setting threadPollSize property.

@Test(invocationCount = 10, threadPoolSize = 3)
public void a() {

}

InvocationCountParallelTest.java
package com.sample.app.tests;

import org.testng.annotations.Test;

public class InvocationCountParallelTest {

  @Test(invocationCount = 10, threadPoolSize = 3)
  public void a() {
    System.out.println("Executed by " + Thread.currentThread().getName());
  }
}

Run ‘InvocationCountParallelTest.java’, you will see below messages in console.
Executed by TestNG-methods-2
Executed by TestNG-methods-3
Executed by TestNG-methods-1
Executed by TestNG-methods-2
Executed by TestNG-methods-1
Executed by TestNG-methods-3
Executed by TestNG-methods-2
Executed by TestNG-methods-2
Executed by TestNG-methods-1
Executed by TestNG-methods-3



Previous                                                    Next                                                    Home

No comments:

Post a Comment