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

Ensure ITestResult injected to @AfterMethod is apt #3007

Merged
merged 1 commit into from
Nov 21, 2023
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,4 +1,5 @@
Current
Fixed: GITHUB-3006: ITestResult injected at @AfterMethod incorrect when a configuration method failed (Krishnan Mahadevan)
Fixed: GITHUB-3003: BeforeClass|AfterClass with inheritedGroups triggers cyclic dependencies (Krishnan Mahadevan)
New: Added @Inherited to the Listeners annotation, allowing it to be used in forming meta-annotations. (Pavlo Glushchenko)
Fixed: GITHUB-2991: Suite attributes map should be thread safe (Krishnan Mahadevan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,9 @@ private ITestResult invokeMethod(
TestResult.copyAttributes(testResult, result);
m_notifier.addSkippedTest(arguments.getTestMethod(), result);
arguments.getTestMethod().incrementCurrentInvocationCount();
testResult.setMethod(arguments.getTestMethod());
invokedMethod = new InvokedMethod(startTime, result);
invokeListenersForSkippedTestResult(result, invokedMethod);
runAfterConfigurations(arguments, suite, testResult);
runAfterConfigurations(arguments, suite, result);
runAfterGroupsConfigurations(arguments);

return result;
Expand Down Expand Up @@ -773,7 +772,7 @@ private static void cleanInterruptStatus() {
}

private void runAfterConfigurations(
TestMethodArguments arguments, XmlSuite suite, TestResult testResult) {
TestMethodArguments arguments, XmlSuite suite, ITestResult testResult) {
ITestNGMethod[] teardownConfigMethods =
TestNgMethodUtils.filterTeardownConfigurationMethods(
arguments.getTestMethod(), arguments.getAfterMethods());
Expand All @@ -795,7 +794,7 @@ private void runAfterGroupsConfigurations(TestMethodArguments arguments) {
private void runConfigMethods(
TestMethodArguments arguments,
XmlSuite suite,
TestResult testResult,
ITestResult testResult,
ITestNGMethod[] teardownConfigMethods) {
ConfigMethodArguments cfgArgs =
new ConfigMethodArguments.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.testng.Assert;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.TestNG;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -76,6 +79,22 @@ public void ensureGroupInheritanceWorksForConfigMethods() {
assertThat(test.configuration.issue3003.TestClassSample.logs).containsAll(expected);
}

@Test(description = "GITHUB-3006")
public void ensureNativelyInjectedTestResultForAfterMethodMatchesTestMethod() {
TestNG testng = create(test.configuration.issue3006.TestClassSample.class);
testng.run();
ITestResult actual = test.configuration.issue3006.TestClassSample.iTestResult;
assertThat(actual.getStatus())
.withFailMessage("The test method status should have been SKIPPED")
.isEqualTo(ITestResult.SKIP);
List<String> skippedDueTo =
actual.getSkipCausedBy().stream()
.map(ITestNGMethod::getQualifiedName)
.collect(Collectors.toList());
assertThat(skippedDueTo)
.containsExactly("test.configuration.issue3006.TestClassSample.beforeMethod");
}

@DataProvider(name = "produceTestClasses")
public Object[][] produceTestClasses() {
return new Object[][] {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package test.configuration.issue3006;

import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class TestClassSample {

public static ITestResult iTestResult;

@BeforeMethod
public void beforeMethod() {
throw new RuntimeException("Exception to simulate configuration error");
}

@Test
public void test() {}

@AfterMethod(alwaysRun = true)
public void afterMethod(ITestResult testResult) {
iTestResult = testResult;
}
}
Loading