O'Reilly logo

TestNg Beginner's Guide by Varun Menon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – running independent test in threads

Perform the following steps to run independent tests in threads:

  1. Create new class with the name IndependentTestThreading under the test.parallelism package and replace the following code in it:
    package test.parallelism;
    import org.testng.annotations.Test;
    
    public class IndependentTestThreading {
    
    @Test(threadPoolSize=3,invocationCount=6,timeOut=1000)
      public void testMethod(){
        Long id = Thread.currentThread().getId();
        System.out.println("Test method executing on thread with id: "+id);
      }
    }

    The preceding test class contains a test method, which prints a message onto the console when executed. The ID of the thread on which the current method is being executed is printed along with the said message. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required