TestNG Tutorial
Introduction to TestNG Configuration and set up of TestNG project Simple TestNG project in IntelliJ IDEA TestNG annotations Assertions in TestNG Difference between assertEquals and assertSame Ignoring the tests in TestNG Grouping the tests timeOut tests in TestNG Exception tests in TestNG dependsOnMethods dependsOnGroups Hard and Soft dependencies Passing parameters using XML file Passing parameters using Data providers Dynamic Data Providers group-by-instances attribute in TestNG XML suite file Test priorities in TestNG invocationCount in TestNG Executing Selenium tests using TestNG Executing TestNG tests using main method Executing JUnit tests from within TestNG Running tests in Parallel in TestNG Executing only failed tests in TestNG TestNG integration with Maven TestNG integration with Gradle Reporter class in TestNG TestNG Reports Execution Listener Test Listener Comparison between JUnit and TestNGInvocation 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!!