Reputation: 1319
I am using TestNG to run data driven tests
My data is read from an external file
I have a retry logic that is essentially a different test method in the same class but retries only the failed entities from the previous test. I am controlling that using priority
Test(dataProvider="customTestDataProvider" , priority = 1)
public void testSomething(final ITestContext testContext , final CustomTestDataItem testData) throws CustomTestException{
setTestData(testData, testContext);
performStep1();
performStep2();
validateResult();
}
@Test(dataProvider="customTestDataProvider" , priority = 2)
public void testSomethingRetry1(final ITestContext testContext ,final CustomTestDataItem testData) throws CustomTestException{
testSomething(testContext , testData);
}
@Test(dataProvider="customTestDataProvider" , priority = 3)
public void testSomethingRetry2(final ITestContext testContext ,final CustomTestDataItem testData) throws CustomTestException{
testSomething(testContext , testData);
}
customTestDataProvider knows which testData item the method has failed for so in testSomethingRetry1
only the failed test data will be supplied
If a test method fails in testSomething
it is retried in testSomethingRetry1
but testNG considers it is failed since it failed in testSomething
So I need a custom logic to determine if the suite has passed or failed. How do i override the testNG result( pass/fail) with the result I have determined ?
Upvotes: 0
Views: 1424
Reputation: 1036
Instead of duplicating test methods I would recommend to use org.testng.IRetryAnalyzer
which basically runs failed test again. You can see some example here http://seleniumeasy.com/testng-tutorials/execute-only-failed-test-cases-using-iretryanalyzer.
But if you really want to override result you can use listeners and implement methods in which you get ITestResult
. In this object you can check method class/name/result/etc. and change some of these attributes (including result).
http://testng.org/javadocs/org/testng/ITestListener.html http://testng.org/javadocs/org/testng/IInvokedMethodListener.html
or for whole test suite
http://testng.org/javadocs/org/testng/ISuiteListener.html
Upvotes: 1