Wednesday, 11 March 2020

TestNG: invocationCount: Invoke test method given number of times

Specifying ‘invocationCount’ property you can invoke the test method given number of times.

Example
@Test(invocationCount = 5)
public void a() {

}

InvocationCountDemo.java
package com.sample.app.tests;

import org.testng.annotations.Test;

public class InvocationCountDemo {

 int count = 0;

 @Test(invocationCount = 5)
 public void a() {
  count++;
  System.out.println("Invoked count : " + count);
 }
}

Run InvocationCountDemo.java, you will see below messages in console.
[RemoteTestNG] detected TestNG version 7.0.0
Invoked count : 1
Invoked count : 2
Invoked count : 3
Invoked count : 4
Invoked count : 5
PASSED: a
PASSED: a
PASSED: a
PASSED: a
PASSED: a

===============================================
    Default test
    Tests run: 5, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 5, Passes: 5, Failures: 0, Skips: 0
===============================================

From the console, it is clear that the test method ran 5 times.




Previous                                                    Next                                                    Home

No comments:

Post a Comment