From bb35913944db5f3a1a053847138c144ab98c2ca2 Mon Sep 17 00:00:00 2001 From: Mohanad49 Date: Tue, 24 Nov 2026 07:40:17 +0200 Subject: [PATCH] Keep the failure status of retried TestNG attempts (fixes #452) TestNG ends an attempt that its retry analyzer retries with the SKIP status, and AllureTestNg reported it as skipped. The attempt actually failed, so the result now carries the status of its throwable: failed for an AssertionError, broken for anything else. Tests skipped for any other reason are still reported as skipped. --- .../io/qameta/allure/testng/AllureTestNg.java | 9 +++- .../allure/testng/AllureTestNgTest.java | 40 ++++++++++++++++ .../testng/samples/RetriedFlakyTest.java | 48 +++++++++++++++++++ .../src/test/resources/suites/retry-flaky.xml | 10 ++++ 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 allure-testng/src/test/java/io/qameta/allure/testng/samples/RetriedFlakyTest.java create mode 100644 allure-testng/src/test/resources/suites/retry-flaky.xml diff --git a/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java b/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java index c00b1ac4e..298dc93c2 100644 --- a/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java +++ b/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java @@ -642,7 +642,14 @@ public void onTestSkipped(final ITestResult result) { } final String uuid = ensureTestStarted(result); - stopTest(uuid, result.getThrowable(), Status.SKIPPED); + final Throwable throwable = result.getThrowable(); + // TestNG reports an attempt that its retry analyzer retries as skipped, although the attempt + // failed. Keep the status of that failure, so the retry shows why it happened. + Status status = Status.SKIPPED; + if (result.wasRetried() && throwable != null) { + status = getStatus(throwable); + } + stopTest(uuid, throwable, status); } /** diff --git a/allure-testng/src/test/java/io/qameta/allure/testng/AllureTestNgTest.java b/allure-testng/src/test/java/io/qameta/allure/testng/AllureTestNgTest.java index 33a388859..7756c8aed 100644 --- a/allure-testng/src/test/java/io/qameta/allure/testng/AllureTestNgTest.java +++ b/allure-testng/src/test/java/io/qameta/allure/testng/AllureTestNgTest.java @@ -1193,6 +1193,46 @@ public void retryTest() { .hasSize(2); } + @AllureFeatures.Retries + @Issue("452") + @Test + @DisplayName("Should keep the failed status of an attempt that TestNG retries") + public void shouldKeepFailedStatusOfRetriedAttempt() { + final AllureResults results = runTestNgSuites("suites/retry-flaky.xml"); + final List attempts = results.getTestResults(); + + assertThat(attempts) + .extracting(TestResult::getName, TestResult::getStatus) + .containsExactlyInAnyOrder( + tuple("passesOnRetry", Status.FAILED), + tuple("passesOnRetry", Status.PASSED) + ); + + final List failureMessages = attempts.stream() + .filter(attempt -> attempt.getStatus() == Status.FAILED) + .map(attempt -> attempt.getStatusDetails().getMessage()) + .collect(Collectors.toList()); + assertThat(failureMessages) + .hasSize(1) + .allSatisfy(message -> assertThat(message).startsWith("Only the retry passes")); + } + + @AllureFeatures.Retries + @Issue("452") + @Test + @DisplayName("Should keep the broken status of an attempt that TestNG retries") + public void shouldKeepBrokenStatusOfRetriedAttempt() { + final AllureResults results = runTestNgSuites("suites/retry.xml"); + final List attempts = results.getTestResults(); + + assertThat(attempts) + .extracting(TestResult::getStatus, attempt -> attempt.getStatusDetails().getMessage()) + .containsExactly( + tuple(Status.BROKEN, "Unexpected failure"), + tuple(Status.BROKEN, "Unexpected failure") + ); + } + @AllureFeatures.MarkerAnnotations @Test @DisplayName("Should support flaky, muted and severity as meta annotations") diff --git a/allure-testng/src/test/java/io/qameta/allure/testng/samples/RetriedFlakyTest.java b/allure-testng/src/test/java/io/qameta/allure/testng/samples/RetriedFlakyTest.java new file mode 100644 index 000000000..725aa3af4 --- /dev/null +++ b/allure-testng/src/test/java/io/qameta/allure/testng/samples/RetriedFlakyTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2016-2026 Qameta Software Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.qameta.allure.testng.samples; + +import org.testng.ITestResult; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.testng.util.RetryAnalyzerCount; + +import java.util.concurrent.atomic.AtomicInteger; + +import static org.testng.Assert.assertEquals; + +public class RetriedFlakyTest { + + private static final AtomicInteger ATTEMPTS = new AtomicInteger(); + + @BeforeClass + public void resetAttempts() { + ATTEMPTS.set(0); + } + + @Test(retryAnalyzer = RetryOnce.class) + public void passesOnRetry() { + assertEquals(ATTEMPTS.incrementAndGet(), 2, "Only the retry passes"); + } + + public static class RetryOnce extends RetryAnalyzerCount { + + @Override + public boolean retryMethod(final ITestResult result) { + return !result.isSuccess(); + } + } +} diff --git a/allure-testng/src/test/resources/suites/retry-flaky.xml b/allure-testng/src/test/resources/suites/retry-flaky.xml new file mode 100644 index 000000000..f0933ea2b --- /dev/null +++ b/allure-testng/src/test/resources/suites/retry-flaky.xml @@ -0,0 +1,10 @@ + + + + + + + + + +