Next-Gen App & Browser
Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles
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.
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.