Skip to content

Commit 0438740

Browse files
authored
Merge pull request testng-team#2732 from bj-9527/github2729
beforeConfiguration() listener method should be invoked for skipped configurations as well
2 parents 331bfbe + f8783af commit 0438740

File tree

8 files changed

+50
-1
lines changed

8 files changed

+50
-1
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Current
22
7.6.0
3+
Fixed: GITHUB-2729: beforeConfiguration() listener method should be invoked for skipped configurations as well(Nan Liang)
34
Fixed: assertEqualsNoOrder for Collection and Iterators size check was missing (Adam Kaczmarek)
45
Fixed: GITHUB-2709: Testnames not working together with suites in suite (Martin Aldrin)
56
Fixed: GITHUB-2704: IHookable and IConfigurable callback discrepancy (Krishnan Mahadevan)

testng-core/src/main/java/org/testng/internal/invokers/ConfigInvoker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ public void invokeConfigurations(ConfigMethodArguments arguments) {
277277
&& !alwaysRun) {
278278
log(3, "Skipping " + Utils.detailedMethodName(tm, true));
279279
InvokedMethod invokedMethod = new InvokedMethod(System.currentTimeMillis(), testResult);
280+
runConfigurationListeners(testResult, arguments.getTestMethod(), true /* before */);
280281
runInvokedMethodListeners(BEFORE_INVOCATION, invokedMethod, testResult);
281282
testResult.setEndMillis(testResult.getStartMillis());
282283
testResult.setStatus(ITestResult.SKIP);

testng-core/src/test/java/test/configuration/ConfigurationListenerTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.testng.TestNG;
55
import org.testng.annotations.Test;
66
import test.SimpleBaseTest;
7+
import test.configuration.issue2729.BeforeConfigSampleListener;
8+
import test.configuration.issue2729.BeforeConfigTestSample;
79

810
public class ConfigurationListenerTest extends SimpleBaseTest {
911

@@ -14,4 +16,11 @@ public void listenerShouldBeCalled() {
1416
tng.run();
1517
Assert.assertTrue(ConfigurationListenerSampleTest.m_passed);
1618
}
19+
20+
@Test(description = "github 2729")
21+
public void beforeConfigShouldExecutedForSkippedConfig() {
22+
TestNG tng = create(BeforeConfigTestSample.class);
23+
tng.run();
24+
Assert.assertEquals(BeforeConfigSampleListener.count, 2);
25+
}
1726
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package test.configuration.issue2729;
2+
3+
import org.testng.IConfigurationListener;
4+
import org.testng.IInvokedMethodListener;
5+
import org.testng.ITestListener;
6+
import org.testng.ITestResult;
7+
8+
public class BeforeConfigSampleListener
9+
implements ITestListener, IInvokedMethodListener, IConfigurationListener {
10+
public static int count = 0;
11+
12+
@Override
13+
public void beforeConfiguration(ITestResult testResult) {
14+
count++;
15+
}
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package test.configuration.issue2729;
2+
3+
import org.testng.annotations.BeforeClass;
4+
import org.testng.annotations.BeforeMethod;
5+
import org.testng.annotations.Listeners;
6+
import org.testng.annotations.Test;
7+
8+
@Listeners({BeforeConfigSampleListener.class})
9+
public class BeforeConfigTestSample {
10+
@BeforeClass
11+
public void beforeClass() {
12+
int i = 5 / 0;
13+
}
14+
15+
@BeforeMethod
16+
public void beforeMethod() {}
17+
18+
@Test
19+
public void sampleTest() {}
20+
}

testng-core/src/test/java/test/listeners/ConfigurationListenerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ public void shouldFail() {
5656

5757
@Test
5858
public void shouldSkip() {
59-
runTest(ConfigurationListenerSkipSampleTest.class, 1 + 5 + 7); // fail + skip
59+
runTest(ConfigurationListenerSkipSampleTest.class, 1 + 1 + 5 + 7); // fail + skip
6060
}
6161
}

testng-core/src/test/java/test/listeners/ordering/ListenerInvocationDefaultBehaviorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public void testOrderHasOnlyFailedAndSkippedConfigAndSkippedTestMethod() {
129129
IINVOKEDMETHODLISTENER_AFTER_INVOCATION,
130130
IINVOKEDMETHODLISTENER_AFTER_INVOCATION_WITH_CONTEXT,
131131
ICONFIGURATIONLISTENER_ON_CONFIGURATION_FAILURE,
132+
ICONFIGURATIONLISTENER_BEFORE_CONFIGURATION,
132133
IINVOKEDMETHODLISTENER_BEFORE_INVOCATION,
133134
IINVOKEDMETHODLISTENER_BEFORE_INVOCATION_WITH_CONTEXT,
134135
IINVOKEDMETHODLISTENER_AFTER_INVOCATION,

testng-core/src/test/java/test/listeners/ordering/ListenerInvocationListenerInvocationDisabledBehaviorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public void testOrderHasOnlyFailedAndSkippedConfigAndSkippedTestMethod() {
126126
IINVOKEDMETHODLISTENER_AFTER_INVOCATION,
127127
IINVOKEDMETHODLISTENER_AFTER_INVOCATION_WITH_CONTEXT,
128128
ICONFIGURATIONLISTENER_ON_CONFIGURATION_FAILURE,
129+
ICONFIGURATIONLISTENER_BEFORE_CONFIGURATION,
129130
IINVOKEDMETHODLISTENER_BEFORE_INVOCATION,
130131
IINVOKEDMETHODLISTENER_BEFORE_INVOCATION_WITH_CONTEXT,
131132
IINVOKEDMETHODLISTENER_AFTER_INVOCATION,

0 commit comments

Comments
 (0)