Skip to content

Commit

Permalink
Merge pull request testng-team#2732 from bj-9527/github2729
Browse files Browse the repository at this point in the history
beforeConfiguration() listener method should be invoked for skipped configurations as well
  • Loading branch information
juherr authored Feb 18, 2022
2 parents 331bfbe + f8783af commit 0438740
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 1 deletion.
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

0 comments on commit 0438740

Please sign in to comment.