Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestResult> attempts = results.getTestResults();

assertThat(attempts)
.extracting(TestResult::getName, TestResult::getStatus)
.containsExactlyInAnyOrder(
tuple("passesOnRetry", Status.FAILED),
tuple("passesOnRetry", Status.PASSED)
);

final List<String> 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<TestResult> 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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
10 changes: 10 additions & 0 deletions allure-testng/src/test/resources/suites/retry-flaky.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Retried flaky suite">
<test name="Retried flaky tests">
<classes>
<class name="io.qameta.allure.testng.samples.RetriedFlakyTest"/>
</classes>
</test>
</suite>