Background: I am using TestNG DataProvider
Requirement: Need to eliminate 1 test from the TestNG report after execution is finished.
My Solution: Suppose, I need to remove the 'XYZ' test case from the report.
String testName = "XYZ";
private void removeTestFromResult(ITestContext context)
{
for (ITestNGMethod testMethodName : context.getAllTestMethods())
{
String testMethod = testMethodName.getMethodName().toLowerCase();
if (testMethod.contains(testName))
{
if (context.getPassedTests().size() > 0)
{
context.getPassedTests().removeResult(testMethodName);
}
if (context.getFailedTests().size() > 0)
{
context.getFailedTests().removeResult(testMethodName);
}
if (context.getSkippedTests().size() > 0)
{
context.getSkippedTests().removeResult(testMethodName);
}
}
}
}