Next-Gen App & Browser
Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

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.

Test Your Website on 3000+ Browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...
ShadowLT Logo

Start your journey with LambdaTest

Get 100 minutes of automation test minutes FREE!!

Signup for free