Skip to content

Commit aafb2d1

Browse files
committed
configfailurepolicy=continue only works for BeforeTest when using TestNG XML file
Fixes testng-team#2731
1 parent 0438740 commit aafb2d1

File tree

7 files changed

+68
-22
lines changed

7 files changed

+68
-22
lines changed

CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Current
22
7.6.0
3+
Fixed: GITHUB-2731: configfailurepolicy=continue only works for BeforeTest when using TestNG XML file (Nan Liang)
34
Fixed: GITHUB-2729: beforeConfiguration() listener method should be invoked for skipped configurations as well(Nan Liang)
45
Fixed: assertEqualsNoOrder for Collection and Iterators size check was missing (Adam Kaczmarek)
56
Fixed: GITHUB-2709: Testnames not working together with suites in suite (Martin Aldrin)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ public void invokeConfigurations(ConfigMethodArguments arguments) {
274274
tm.getGroups(),
275275
arguments.getTestClass(),
276276
arguments.getInstance())
277-
&& !alwaysRun) {
277+
&& !alwaysRun
278+
&& !m_continueOnFailedConfiguration) {
278279
log(3, "Skipping " + Utils.detailedMethodName(tm, true));
279280
InvokedMethod invokedMethod = new InvokedMethod(System.currentTimeMillis(), testResult);
280281
runConfigurationListeners(testResult, arguments.getTestMethod(), true /* before */);

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,8 @@ private ITestResult invokeMethod(
597597
arguments.getTestMethod(),
598598
arguments.getTestMethod().getGroups(),
599599
arguments.getTestClass(),
600-
arguments.getInstance())) {
600+
arguments.getInstance())
601+
&& suite.getConfigFailurePolicy() == XmlSuite.FailurePolicy.SKIP) {
601602
Throwable exception =
602603
ExceptionUtils.getExceptionDetails(m_testContext, arguments.getInstance());
603604
ITestResult result =

testng-core/src/test/java/test/configurationfailurepolicy/FailurePolicyTest.java

+19-17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.testng.annotations.DataProvider;
1111
import org.testng.annotations.Test;
1212
import org.testng.xml.XmlSuite;
13+
import test.configurationfailurepolicy.issue2731.ConfigFailTestSample;
1314
import testhelper.OutputDirectoryPatch;
1415

1516
public class FailurePolicyTest {
@@ -26,32 +27,33 @@ public void setupClass(ITestContext testContext) {
2627
public Object[][] getData() {
2728
return new Object[][] {
2829
// params - confFail, confSkip, skippedTests
29-
new Object[] {new Class[] {ClassWithFailedBeforeClassMethod.class}, 1, 1, 1},
30-
new Object[] {new Class[] {ClassWithFailedBeforeClassMethodAndAfterClass.class}, 1, 1, 1},
31-
new Object[] {new Class[] {ClassWithFailedBeforeMethodAndMultipleTests.class}, 2, 0, 2},
30+
new Object[] {new Class[] {ClassWithFailedBeforeClassMethod.class}, 1, 0, 0},
31+
new Object[] {new Class[] {ClassWithFailedBeforeClassMethodAndAfterClass.class}, 1, 0, 0},
32+
new Object[] {new Class[] {ClassWithFailedBeforeMethodAndMultipleTests.class}, 2, 0, 0},
3233
new Object[] {
3334
new Class[] {ClassWithFailedBeforeClassMethodAndBeforeMethodAfterMethodAfterClass.class},
3435
1,
35-
3,
36-
1
36+
0,
37+
0
3738
},
38-
new Object[] {new Class[] {ClassWithFailedBeforeMethodAndMultipleInvocations.class}, 4, 0, 4},
39-
new Object[] {new Class[] {ExtendsClassWithFailedBeforeMethod.class}, 2, 2, 2},
40-
new Object[] {new Class[] {ExtendsClassWithFailedBeforeClassMethod.class}, 1, 2, 2},
39+
new Object[] {new Class[] {ClassWithFailedBeforeMethodAndMultipleInvocations.class}, 4, 0, 0},
40+
new Object[] {new Class[] {ExtendsClassWithFailedBeforeMethod.class}, 2, 0, 0},
41+
new Object[] {new Class[] {ExtendsClassWithFailedBeforeClassMethod.class}, 1, 0, 0},
4142
new Object[] {
4243
new Class[] {
4344
ClassWithFailedBeforeClassMethod.class, ExtendsClassWithFailedBeforeClassMethod.class
4445
},
4546
2,
46-
3,
47-
3
47+
0,
48+
0
4849
},
49-
new Object[] {new Class[] {ClassWithSkippingBeforeMethod.class}, 0, 1, 1},
50-
new Object[] {new Class[] {FactoryClassWithFailedBeforeMethod.class}, 2, 0, 2},
50+
new Object[] {new Class[] {ClassWithSkippingBeforeMethod.class}, 0, 1, 0},
51+
new Object[] {new Class[] {FactoryClassWithFailedBeforeMethod.class}, 2, 0, 0},
5152
new Object[] {
52-
new Class[] {FactoryClassWithFailedBeforeMethodAndMultipleInvocations.class}, 8, 0, 8
53+
new Class[] {FactoryClassWithFailedBeforeMethodAndMultipleInvocations.class}, 8, 0, 0
5354
},
54-
new Object[] {new Class[] {FactoryClassWithFailedBeforeClassMethod.class}, 2, 2, 2},
55+
new Object[] {new Class[] {FactoryClassWithFailedBeforeClassMethod.class}, 2, 0, 0},
56+
new Object[] {new Class[] {ConfigFailTestSample.class}, 4, 0, 0}
5557
};
5658
}
5759

@@ -86,7 +88,7 @@ public void confFailureTestInvolvingGroups() {
8688
testng.setConfigFailurePolicy(XmlSuite.FailurePolicy.CONTINUE);
8789
testng.setGroups("group1");
8890
testng.run();
89-
verify(tla, 1, 3, 1);
91+
verify(tla, 1, 0, 0);
9092
}
9193

9294
@Test
@@ -124,7 +126,7 @@ public void commandLineTest_policyAsContinue() {
124126
TestListenerAdapter tla = new TestListenerAdapter();
125127
TestNG.privateMain(argv, tla);
126128

127-
verify(tla, 2, 0, 2);
129+
verify(tla, 2, 0, 0);
128130
}
129131

130132
@Test
@@ -160,7 +162,7 @@ public void commandLineTestWithXMLFile_policyAsContinue() {
160162
TestListenerAdapter tla = new TestListenerAdapter();
161163
TestNG.privateMain(argv, tla);
162164

163-
verify(tla, 2, 0, 2);
165+
verify(tla, 2, 0, 0);
164166
}
165167

166168
private void verify(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package test.configurationfailurepolicy.issue2731;
2+
3+
import org.testng.Assert;
4+
import org.testng.annotations.BeforeClass;
5+
import org.testng.annotations.BeforeMethod;
6+
import org.testng.annotations.BeforeSuite;
7+
import org.testng.annotations.BeforeTest;
8+
import org.testng.annotations.Test;
9+
10+
public class ConfigFailTestSample {
11+
@BeforeSuite
12+
public void beforeSuite() {
13+
Assert.fail("This before suite is fail");
14+
}
15+
16+
@BeforeTest
17+
public void beforeTest() {
18+
Assert.fail("This before test is fail");
19+
}
20+
21+
@BeforeClass
22+
public void beforeClass() {
23+
Assert.fail("This before class is fail");
24+
}
25+
26+
@BeforeMethod
27+
public void beforeMethod() {
28+
Assert.fail("This before method is fail");
29+
}
30+
31+
@Test
32+
public void test() {}
33+
}

testng-core/src/test/java/test/listeners/github1602/IssueTest.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,27 @@ public Object[][] getData() {
3535
"BeforeInvocation_afterMethod_STARTED",
3636
"AfterInvocation_afterMethod_SUCCESS");
3737
List<String> baseList =
38+
Arrays.asList(
39+
"BeforeInvocation_beforeMethod_STARTED",
40+
"AfterInvocation_beforeMethod_FAILURE",
41+
"BeforeInvocation_testMethod_STARTED",
42+
"AfterInvocation_testMethod_SUCCESS",
43+
"BeforeInvocation_afterMethod_STARTED");
44+
List<String> commonSkipList =
3845
Arrays.asList(
3946
"BeforeInvocation_beforeMethod_STARTED",
4047
"AfterInvocation_beforeMethod_FAILURE",
4148
"BeforeInvocation_testMethod_SKIP",
4249
"AfterInvocation_testMethod_SKIP",
43-
"BeforeInvocation_afterMethod_STARTED");
50+
"BeforeInvocation_afterMethod_STARTED",
51+
"AfterInvocation_afterMethod_SKIP");
4452
List<String> skipList = Lists.newArrayList(baseList);
4553
skipList.add("AfterInvocation_afterMethod_SKIP");
4654
List<String> failList = Lists.newArrayList(baseList);
4755
failList.add("AfterInvocation_afterMethod_FAILURE");
4856
return new Object[][] {
4957
{TestClassWithPassingConfigsSample.class, XmlSuite.FailurePolicy.SKIP, passList},
50-
{TestClassWithFailingConfigsSample.class, XmlSuite.FailurePolicy.SKIP, skipList},
58+
{TestClassWithFailingConfigsSample.class, XmlSuite.FailurePolicy.SKIP, commonSkipList},
5159
{TestClassWithPassingConfigsSample.class, XmlSuite.FailurePolicy.CONTINUE, passList},
5260
{TestClassWithFailingConfigsSample.class, XmlSuite.FailurePolicy.CONTINUE, failList}
5361
};

testng-core/src/test/java/test/listeners/issue1777/IssueTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void testOnStartInvokedForSkippedTests() {
2828
"before_test_method: test1",
2929
"after_test_method: test1",
3030
"after_test_method: test1",
31-
"testSkipped_test_method: test1",
31+
"testSuccess_test_method: test1",
3232
"testStart_test_method: test2",
3333
"before_test_method: test2",
3434
"before_test_method: test2",

0 commit comments

Comments
 (0)