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

beforeConfiguration() listener method should be invoked for skipped configurations as well #2732

Merged
merged 1 commit into from
Feb 18, 2022
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.6.0
Fixed: GITHUB-2729: beforeConfiguration() listener method should be invoked for skipped configurations as well(Nan Liang)
Fixed: assertEqualsNoOrder for Collection and Iterators size check was missing (Adam Kaczmarek)
Fixed: GITHUB-2709: Testnames not working together with suites in suite (Martin Aldrin)
Fixed: GITHUB-2704: IHookable and IConfigurable callback discrepancy (Krishnan Mahadevan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ public void invokeConfigurations(ConfigMethodArguments arguments) {
&& !alwaysRun) {
log(3, "Skipping " + Utils.detailedMethodName(tm, true));
InvokedMethod invokedMethod = new InvokedMethod(System.currentTimeMillis(), testResult);
runConfigurationListeners(testResult, arguments.getTestMethod(), true /* before */);
runInvokedMethodListeners(BEFORE_INVOCATION, invokedMethod, testResult);
testResult.setEndMillis(testResult.getStartMillis());
testResult.setStatus(ITestResult.SKIP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.testng.TestNG;
import org.testng.annotations.Test;
import test.SimpleBaseTest;
import test.configuration.issue2729.BeforeConfigSampleListener;
import test.configuration.issue2729.BeforeConfigTestSample;

public class ConfigurationListenerTest extends SimpleBaseTest {

Expand All @@ -14,4 +16,11 @@ public void listenerShouldBeCalled() {
tng.run();
Assert.assertTrue(ConfigurationListenerSampleTest.m_passed);
}

@Test(description = "github 2729")
public void beforeConfigShouldExecutedForSkippedConfig() {
TestNG tng = create(BeforeConfigTestSample.class);
tng.run();
Assert.assertEquals(BeforeConfigSampleListener.count, 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package test.configuration.issue2729;

import org.testng.IConfigurationListener;
import org.testng.IInvokedMethodListener;
import org.testng.ITestListener;
import org.testng.ITestResult;

public class BeforeConfigSampleListener
implements ITestListener, IInvokedMethodListener, IConfigurationListener {
public static int count = 0;

@Override
public void beforeConfiguration(ITestResult testResult) {
count++;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package test.configuration.issue2729;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners({BeforeConfigSampleListener.class})
public class BeforeConfigTestSample {
@BeforeClass
public void beforeClass() {
int i = 5 / 0;
}

@BeforeMethod
public void beforeMethod() {}

@Test
public void sampleTest() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ public void shouldFail() {

@Test
public void shouldSkip() {
runTest(ConfigurationListenerSkipSampleTest.class, 1 + 5 + 7); // fail + skip
runTest(ConfigurationListenerSkipSampleTest.class, 1 + 1 + 5 + 7); // fail + skip
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void testOrderHasOnlyFailedAndSkippedConfigAndSkippedTestMethod() {
IINVOKEDMETHODLISTENER_AFTER_INVOCATION,
IINVOKEDMETHODLISTENER_AFTER_INVOCATION_WITH_CONTEXT,
ICONFIGURATIONLISTENER_ON_CONFIGURATION_FAILURE,
ICONFIGURATIONLISTENER_BEFORE_CONFIGURATION,
IINVOKEDMETHODLISTENER_BEFORE_INVOCATION,
IINVOKEDMETHODLISTENER_BEFORE_INVOCATION_WITH_CONTEXT,
IINVOKEDMETHODLISTENER_AFTER_INVOCATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void testOrderHasOnlyFailedAndSkippedConfigAndSkippedTestMethod() {
IINVOKEDMETHODLISTENER_AFTER_INVOCATION,
IINVOKEDMETHODLISTENER_AFTER_INVOCATION_WITH_CONTEXT,
ICONFIGURATIONLISTENER_ON_CONFIGURATION_FAILURE,
ICONFIGURATIONLISTENER_BEFORE_CONFIGURATION,
IINVOKEDMETHODLISTENER_BEFORE_INVOCATION,
IINVOKEDMETHODLISTENER_BEFORE_INVOCATION_WITH_CONTEXT,
IINVOKEDMETHODLISTENER_AFTER_INVOCATION,
Expand Down