Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy test result attributes when unexpected failures #3065

Merged
merged 1 commit into from
Feb 12, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Current
7.10.0
Fixed: GITHUB-3064: TestResult lost if failure creating RetryAnalyzer (Krishnan Mahadevan)
Fixed: GITHUB-3048: ConcurrentModificationException when injecting values (Krishnan Mahadevan)
Fixed: GITHUB-3050: Race condition when creating Guice Modules (Krishnan Mahadevan)
Fixed: GITHUB-3059: Support the ability to inject custom listener factory (Krishnan Mahadevan)
Comment on lines 1 to 6
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The verification process for the issues mentioned in the CHANGES.txt file for version 7.10.0 reveals the following:

  • GITHUB-3064 is still OPEN and assigned to milestone 7.10.0. This indicates that it might not be accurately resolved in this version as mentioned.
  • GITHUB-3048, GITHUB-3050, GITHUB-3059, and GITHUB-3045 are CLOSED and correctly assigned to milestone 7.10.0, aligning with the summary of changes.

Given this discrepancy with GITHUB-3064, it appears there is an issue with the completeness of the resolution as documented in the CHANGES.txt file for version 7.10.0.

Analysis chain

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [3-7]

The summary of changes for version 7.10.0 should be consistent with the project's versioning history and the detailed list of changes provided in the file. Confirm that all mentioned issues (e.g., GITHUB-3064, GITHUB-3048) are accurately resolved in this version.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the resolution of mentioned GitHub issues
gh issue view 3064 --repo testng-team/testng
gh issue view 3048 --repo testng-team/testng
gh issue view 3050 --repo testng-team/testng
gh issue view 3059 --repo testng-team/testng
gh issue view 3045 --repo testng-team/testng
gh issue view 3038 --repo testng-team/testng
gh issue view 3022 --repo testng-team/testng

Length of output: 19211

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,8 @@ public int invoke(int invCount) {
ITestResult r =
TestResult.newEndTimeAwareTestResult(
arguments.getTestMethod(), m_testContext, cause, start);
Optional.ofNullable(Reporter.getCurrentTestResult())
.ifPresent(it -> TestResult.copyAttributes(it, r));
r.setStatus(TestResult.FAILURE);
result.add(r);
runTestResultListener(r);
Expand Down
10 changes: 10 additions & 0 deletions testng-core/src/test/java/test/listeners/ListenersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import test.listeners.issue2880.ListenerForIssue2880;
import test.listeners.issue2880.TestClassWithFailingConfigsSample;
import test.listeners.issue2880.TestClassWithPassingConfigsSample;
import test.listeners.issue3064.EvidenceListener;
import test.listeners.issue3064.SampleTestCase;

public class ListenersTest extends SimpleBaseTest {

Expand All @@ -37,6 +39,14 @@ public class ListenersTest extends SimpleBaseTest {
"test.listeners.issue2638.TestClassBSample.testMethod"
};

@Test(description = "GITHUB-3064")
public void ensureTestResultAttributesAreCarriedForward() {
TestNG testng = create(SampleTestCase.class);
testng.run();
assertThat(EvidenceListener.failureTestResult.getAttribute(EvidenceListener.ATTRIBUTE_KEY))
.isEqualTo("attributeValue");
}

@Test(description = "GITHUB-2638", dataProvider = "suiteProvider")
public void ensureDuplicateListenersAreNotWiredInAcrossSuites(
XmlSuite xmlSuite, Map<String, String[]> expected) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test.listeners.issue3064;

import org.testng.ITestListener;
import org.testng.ITestResult;

public class EvidenceListener implements ITestListener {
public static final String ATTRIBUTE_KEY = "attributeKey";
public static ITestResult failureTestResult;

@Override
public void onTestStart(ITestResult result) {
result.setAttribute(ATTRIBUTE_KEY, "attributeValue");
}

@Override
public void onTestFailure(ITestResult result) {
failureTestResult = result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package test.listeners.issue3064;

import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;

public class EvidenceRetryAnalyzer implements IRetryAnalyzer {

public EvidenceRetryAnalyzer() {
throw new RuntimeException("Failed on purpose");
}

@Override
public boolean retry(ITestResult result) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package test.listeners.issue3064;

import static org.testng.Assert.fail;

import org.testng.ITestContext;
import org.testng.ITestNGMethod;
import org.testng.Reporter;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Test
@Listeners(EvidenceListener.class)
public class SampleTestCase {

@BeforeSuite(alwaysRun = true)
public void suiteSetup() {
ITestContext context = Reporter.getCurrentTestResult().getTestContext();
for (ITestNGMethod method : context.getAllTestMethods()) {
method.setRetryAnalyzerClass(EvidenceRetryAnalyzer.class);
}
}

@Test
public void testOne() {
fail();
}
}
Loading