Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.
When you wish to run the same tests several times, you use invocation count. In TestNG, the @Test(invocationCount=x) annotation defines the number of times a test method is performed. The annotation's x value indicates how often the test method should be called. The following example shows how to use invocation count in TestNG.
For instance, if a test method needs to be run five times to ensure its reliability, you may use the @Test(invocationCount=5) annotation to run it five times. Here is the code snippet for this example:
@Test(invocationCount=5)
public void testAddition() {
Calculator calc = new Calculator();
int result = calc.add(2, 3);
Assert.assertEquals(result, 5);
}
You can visit our detailed blog about TestNG annotations, where we have covered every important annotations in TestNG.
Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.
Start Free TestingEarn resume-worthy Selenium certifications that help you land a top job.
Learn MoreTest orchestration and execution cloud of 3000+ browsers and OS
24/7 support
Enterprise grade security
Fastest test execution cloud