Search code examples
javatestng

Total count of tests before test suite from dataprovider send to listener


Hello guys so I have 10files and 10 tests in my suite. Each test have one DATA PROVIDER what return String[].I know how to get length of all String[] from all data providers. Lets say total count of all tests in suite is 50.This value I count @BeforeClass

My question is : How can I send this total number to my suite listener before suite start? Or right after it start? Because I want use this number to calculate my threshold for skip tests etc.

I already tried setAttribute() for ITestContext and ISuite interfaces in my test class but even if I do it @BeforeClass or in @Test then it is always null in my listener class in OnStart(ITestContext context) or OnStart(ISuite suite).

Thanks for any help in advance.

1 - this methods find how many values are in all data providers what will be used in tests

enter image description here

2 - here is use value what was counted in previous step and set it as suite attribute

enter image description here

3- in my listener class i am trying to get suite attribute but it is always null

enter image description here

Sorry for pictures but no code but i was unable to format it correctly.

Simply what i want is to pass this total test number to listener so i can use it and count e.g. if more then 10% test fail all other will be skip(but for this i ne to know total amount of tests).But I have this logic that is no problem but I need to know how to pass this total number of tests to listener. Normally if I dont use data provider I just use suite.GetAllMethods() and thats it , but this is not apply for dataproviders so i need pass this total ammount of tests different way then i am used to and cant figure ut how.


Solution

  • Problem solved.

    In listener class I must get suite attribute in OnTestStart(ITestResult) instead of OnStart(ISuite)

      @Override
     protected void OnTestStart(ITestResult tr) {  
        totalTests = (Integer) tr.getTestContext().getAttribute("Total tests");        
    }
    

    }