I am wondering how to get the count of total number of test cases which are being executed in a testng suite for displaying it in testng customized report.As of now we are able to get the passed failed and skipped tests. Please enlighten.
Asked
Active
Viewed 76 times
0
-
3Just add them up... – Grasshopper May 30 '18 at 07:11
-
Adding them is quite unstable, it does not remain in sync. – testergirl May 30 '18 at 09:52
-
1Use a AtomicInteger. https://stackoverflow.com/questions/4818699/practical-uses-for-atomicinteger – Grasshopper May 30 '18 at 10:04
1 Answers
0
@Grasshoper's solutions sound good, just add them up, its quiet simple.
But if You using selenium/testng, try implementing methods by adding implements ITestListener
to Your class and how have to implement this interface methods:
public interface ITestListener extends ITestNGListener {
public void onTestStart(ITestResult result);
public void onTestSuccess(ITestResult result);
public void onTestFailure(ITestResult result);
public void onTestSkipped(ITestResult result);
public void onTestFailedButWithinSuccessPercentage(ITestResult result);
public void onStart(ITestContext context);
public void onFinish(ITestContext context);
and if You want to know exact number input code bellow to get all test methods:
public synchronized void onStart(ITestContext context) {
TestRunner tRunner = (TestRunner) context;
ITestNGMethod[] testMethods = tRunner.getAllTestMethods();
int count = testMethods.length;
}
Hope this helps...

Kovacic
- 1,473
- 6
- 21
-
Yes it works, @Override public void onStart(ITestContext testContext) { super.onStart(testContext); int total=testContext.getAllTestMethods().length; – testergirl May 30 '18 at 09:51
-