In the current project, skipped and failed tests are retried twice. A test is removed from the test results if it was skipped or failed the first time to avoid duplication.
public void onFinish(ISuite suite) {
Map<String, ISuiteResult> passedTests = suite.getResults();
//remove passed tests from failed tests and skipped tests
for (ISuiteResult r : passedTests.values()) {
ITestContext context = r.getTestContext();
context.getPassedTests().getAllResults().forEach(i -> {
if (context.getFailedTests().getAllMethods().contains(i.getMethod())) {
context.getFailedTests().removeResult(i.getMethod());
}
if (context.getSkippedTests().getAllMethods().contains(i.getMethod())) {
context.getSkippedTests().removeResult(i.getMethod());
}
});
//remove skipped tests from failed tests
context.getFailedTests().getAllResults().forEach(i -> {
log.info("Going to remove test case: " + i.getMethod());
if (context.getSkippedTests().getAllMethods().contains(i.getMethod())) {
context.getSkippedTests().removeResult(i.getMethod());
Reporter.log("Skipped tests for suite '" + suite.getName() +
"' is:" + context.getSkippedTests().getAllResults().size(), true);
}
});
}
}
In such a case, TestNG generates the correct test result (1 test, not 2).
But the Maven Surefire plugin still shows 2 tests – one skipped and one failed.
How can I make the Maven Surefire plugin show only the last test execution?
Unfortunately, I need the Maven Surefire plugin results in JUnit format because we need integration with Zephyr, and we use a plugin Zephyr Scale that can only parse JUnit results. After each Jenkins build, a test cycle is created in Zephyr. However, retried tests are marked as skipped, not failed in Zephyr, because Test-*.xml contains both the same test marked as skipped and failed.
Alternatively, how can I publish the TestNG results to Zephyr based on testng-results.xml?