Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

What is the use of @Test(invocationCount=x)?

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.

LambdaTest

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing
LambdaTest

Earn resume-worthy Selenium certifications that help you land a top job.

Learn More
LambdaTest

Test your web or mobile apps

Test orchestration and execution cloud of 3000+ browsers and OS

Support

24/7 support

Security

Enterprise grade security

Cloud

Fastest test execution cloud