Skip to content

Commit

Permalink
beforeConfiguration() listener method should be invoked for skipped c…
Browse files Browse the repository at this point in the history
…onfigurations as well

Fixes #2729
  • Loading branch information
bj-9527 committed Feb 18, 2022
1 parent 331bfbe commit f8783af
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -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
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
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);
}
}
@@ -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++;
}
}
@@ -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() {}
}
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
}
}
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
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 f8783af

Please sign in to comment.