Invocation count in testng

Invocation count is used when you want to run the same tests multiple times. Below example illustrates how to use invocation count in TestNG. In below example, test1 will be executed 5 times. We have also used threadPoolSize parameter with value as 2. It means that 2 threads will be created to run the test in parallel.
 
package org.softpost;

import org.testng.annotations.Test;

import java.util.concurrent.atomic.AtomicInteger;

public class InvocationTest {
    AtomicInteger sequence = new AtomicInteger(0);

    @Test(invocationCount = 5, threadPoolSize = 2)
    public void test1(){
        int count= sequence.addAndGet(1);
        System.out.println("Test Run Number  "+
                count + " run by Thread  " + Thread.currentThread().getId());
    }
}

Here is the output of above example –
 
[TestNG] Running:
C:UsersSagar.IdeaIC15system	emp-testng-customsuite.xml
Test Run Number 1 run by Thread 11
Test Run Number 2 run by Thread 12
Test Run Number 3 run by Thread 12
Test Run Number 4 run by Thread 12
Test Run Number 5 run by Thread 12

===============================================
Default Suite
Total tests run: 5, Failures: 0, Skips: 0
===============================================

Web development and Automation testing

solutions delivered!!