Search code examples
javareporttestngcustomization

TestNg Customized report:


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.


Solution

  • @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...