Skip to content

Commit

Permalink
configfailurepolicy=continue only works for BeforeTest when using Tes…
Browse files Browse the repository at this point in the history
…tNG XML file

Fixes testng-team#2731
  • Loading branch information
bj-9527 committed Feb 24, 2022
1 parent 0438740 commit aafb2d1
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 22 deletions.
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-2731: configfailurepolicy=continue only works for BeforeTest when using TestNG XML file (Nan Liang)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ public void invokeConfigurations(ConfigMethodArguments arguments) {
tm.getGroups(),
arguments.getTestClass(),
arguments.getInstance())
&& !alwaysRun) {
&& !alwaysRun
&& !m_continueOnFailedConfiguration) {
log(3, "Skipping " + Utils.detailedMethodName(tm, true));
InvokedMethod invokedMethod = new InvokedMethod(System.currentTimeMillis(), testResult);
runConfigurationListeners(testResult, arguments.getTestMethod(), true /* before */);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ private ITestResult invokeMethod(
arguments.getTestMethod(),
arguments.getTestMethod().getGroups(),
arguments.getTestClass(),
arguments.getInstance())) {
arguments.getInstance())
&& suite.getConfigFailurePolicy() == XmlSuite.FailurePolicy.SKIP) {
Throwable exception =
ExceptionUtils.getExceptionDetails(m_testContext, arguments.getInstance());
ITestResult result =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.xml.XmlSuite;
import test.configurationfailurepolicy.issue2731.ConfigFailTestSample;
import testhelper.OutputDirectoryPatch;

public class FailurePolicyTest {
Expand All @@ -26,32 +27,33 @@ public void setupClass(ITestContext testContext) {
public Object[][] getData() {
return new Object[][] {
// params - confFail, confSkip, skippedTests
new Object[] {new Class[] {ClassWithFailedBeforeClassMethod.class}, 1, 1, 1},
new Object[] {new Class[] {ClassWithFailedBeforeClassMethodAndAfterClass.class}, 1, 1, 1},
new Object[] {new Class[] {ClassWithFailedBeforeMethodAndMultipleTests.class}, 2, 0, 2},
new Object[] {new Class[] {ClassWithFailedBeforeClassMethod.class}, 1, 0, 0},
new Object[] {new Class[] {ClassWithFailedBeforeClassMethodAndAfterClass.class}, 1, 0, 0},
new Object[] {new Class[] {ClassWithFailedBeforeMethodAndMultipleTests.class}, 2, 0, 0},
new Object[] {
new Class[] {ClassWithFailedBeforeClassMethodAndBeforeMethodAfterMethodAfterClass.class},
1,
3,
1
0,
0
},
new Object[] {new Class[] {ClassWithFailedBeforeMethodAndMultipleInvocations.class}, 4, 0, 4},
new Object[] {new Class[] {ExtendsClassWithFailedBeforeMethod.class}, 2, 2, 2},
new Object[] {new Class[] {ExtendsClassWithFailedBeforeClassMethod.class}, 1, 2, 2},
new Object[] {new Class[] {ClassWithFailedBeforeMethodAndMultipleInvocations.class}, 4, 0, 0},
new Object[] {new Class[] {ExtendsClassWithFailedBeforeMethod.class}, 2, 0, 0},
new Object[] {new Class[] {ExtendsClassWithFailedBeforeClassMethod.class}, 1, 0, 0},
new Object[] {
new Class[] {
ClassWithFailedBeforeClassMethod.class, ExtendsClassWithFailedBeforeClassMethod.class
},
2,
3,
3
0,
0
},
new Object[] {new Class[] {ClassWithSkippingBeforeMethod.class}, 0, 1, 1},
new Object[] {new Class[] {FactoryClassWithFailedBeforeMethod.class}, 2, 0, 2},
new Object[] {new Class[] {ClassWithSkippingBeforeMethod.class}, 0, 1, 0},
new Object[] {new Class[] {FactoryClassWithFailedBeforeMethod.class}, 2, 0, 0},
new Object[] {
new Class[] {FactoryClassWithFailedBeforeMethodAndMultipleInvocations.class}, 8, 0, 8
new Class[] {FactoryClassWithFailedBeforeMethodAndMultipleInvocations.class}, 8, 0, 0
},
new Object[] {new Class[] {FactoryClassWithFailedBeforeClassMethod.class}, 2, 2, 2},
new Object[] {new Class[] {FactoryClassWithFailedBeforeClassMethod.class}, 2, 0, 0},
new Object[] {new Class[] {ConfigFailTestSample.class}, 4, 0, 0}
};
}

Expand Down Expand Up @@ -86,7 +88,7 @@ public void confFailureTestInvolvingGroups() {
testng.setConfigFailurePolicy(XmlSuite.FailurePolicy.CONTINUE);
testng.setGroups("group1");
testng.run();
verify(tla, 1, 3, 1);
verify(tla, 1, 0, 0);
}

@Test
Expand Down Expand Up @@ -124,7 +126,7 @@ public void commandLineTest_policyAsContinue() {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG.privateMain(argv, tla);

verify(tla, 2, 0, 2);
verify(tla, 2, 0, 0);
}

@Test
Expand Down Expand Up @@ -160,7 +162,7 @@ public void commandLineTestWithXMLFile_policyAsContinue() {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG.privateMain(argv, tla);

verify(tla, 2, 0, 2);
verify(tla, 2, 0, 0);
}

private void verify(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package test.configurationfailurepolicy.issue2731;

import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ConfigFailTestSample {
@BeforeSuite
public void beforeSuite() {
Assert.fail("This before suite is fail");
}

@BeforeTest
public void beforeTest() {
Assert.fail("This before test is fail");
}

@BeforeClass
public void beforeClass() {
Assert.fail("This before class is fail");
}

@BeforeMethod
public void beforeMethod() {
Assert.fail("This before method is fail");
}

@Test
public void test() {}
}
12 changes: 10 additions & 2 deletions testng-core/src/test/java/test/listeners/github1602/IssueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,27 @@ public Object[][] getData() {
"BeforeInvocation_afterMethod_STARTED",
"AfterInvocation_afterMethod_SUCCESS");
List<String> baseList =
Arrays.asList(
"BeforeInvocation_beforeMethod_STARTED",
"AfterInvocation_beforeMethod_FAILURE",
"BeforeInvocation_testMethod_STARTED",
"AfterInvocation_testMethod_SUCCESS",
"BeforeInvocation_afterMethod_STARTED");
List<String> commonSkipList =
Arrays.asList(
"BeforeInvocation_beforeMethod_STARTED",
"AfterInvocation_beforeMethod_FAILURE",
"BeforeInvocation_testMethod_SKIP",
"AfterInvocation_testMethod_SKIP",
"BeforeInvocation_afterMethod_STARTED");
"BeforeInvocation_afterMethod_STARTED",
"AfterInvocation_afterMethod_SKIP");
List<String> skipList = Lists.newArrayList(baseList);
skipList.add("AfterInvocation_afterMethod_SKIP");
List<String> failList = Lists.newArrayList(baseList);
failList.add("AfterInvocation_afterMethod_FAILURE");
return new Object[][] {
{TestClassWithPassingConfigsSample.class, XmlSuite.FailurePolicy.SKIP, passList},
{TestClassWithFailingConfigsSample.class, XmlSuite.FailurePolicy.SKIP, skipList},
{TestClassWithFailingConfigsSample.class, XmlSuite.FailurePolicy.SKIP, commonSkipList},
{TestClassWithPassingConfigsSample.class, XmlSuite.FailurePolicy.CONTINUE, passList},
{TestClassWithFailingConfigsSample.class, XmlSuite.FailurePolicy.CONTINUE, failList}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void testOnStartInvokedForSkippedTests() {
"before_test_method: test1",
"after_test_method: test1",
"after_test_method: test1",
"testSkipped_test_method: test1",
"testSuccess_test_method: test1",
"testStart_test_method: test2",
"before_test_method: test2",
"before_test_method: test2",
Expand Down

0 comments on commit aafb2d1

Please sign in to comment.