-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
configfailurepolicy=continue only works for BeforeTest when using TestNG XML file #2735
Open
bj-9527
wants to merge
1
commit into
testng-team:master
Choose a base branch
from
bj-9527:github2731
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
testng-core/src/test/java/test/configurationfailurepolicy/FailureContinuePolicyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package test.configurationfailurepolicy; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static test.SimpleBaseTest.getPathToResource; | ||
|
||
import org.testng.ITestContext; | ||
import org.testng.TestListenerAdapter; | ||
import org.testng.TestNG; | ||
import org.testng.annotations.BeforeClass; | ||
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 FailureContinuePolicyTest { | ||
// only if this is run from an xml file that sets this on the suite | ||
@BeforeClass(enabled = false) | ||
public void setupClass(ITestContext testContext) { | ||
assertEquals( | ||
testContext.getSuite().getXmlSuite().getConfigFailurePolicy(), | ||
XmlSuite.FailurePolicy.CONTINUE); | ||
} | ||
|
||
@DataProvider(name = "dp") | ||
public Object[][] getData() { | ||
return new Object[][] { | ||
// params - confFail, confSkip, skippedTests | ||
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, | ||
0, | ||
0 | ||
}, | ||
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, | ||
0, | ||
0 | ||
}, | ||
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, 0 | ||
}, | ||
new Object[] {new Class[] {FactoryClassWithFailedBeforeClassMethod.class}, 2, 0, 0}, | ||
new Object[] {new Class[] {ConfigFailTestSample.class}, 4, 0, 0} | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "dp") | ||
public void confFailureTest( | ||
Class[] classesUnderTest, | ||
int configurationFailures, | ||
int configurationSkips, | ||
int skippedTests) { | ||
|
||
TestListenerAdapter tla = new TestListenerAdapter(); | ||
TestNG testng = new TestNG(); | ||
testng.setOutputDirectory(OutputDirectoryPatch.getOutputDirectory()); | ||
testng.setTestClasses(classesUnderTest); | ||
testng.addListener(tla); | ||
testng.setConfigFailurePolicy(XmlSuite.FailurePolicy.CONTINUE); | ||
testng.run(); | ||
|
||
verify(tla, configurationFailures, configurationSkips, skippedTests); | ||
} | ||
|
||
@Test | ||
public void confFailureTestInvolvingGroups() { | ||
Class[] classesUnderTest = | ||
new Class[] {ClassWithFailedBeforeClassMethodAndBeforeGroupsAfterClassAfterGroups.class}; | ||
|
||
TestListenerAdapter tla = new TestListenerAdapter(); | ||
TestNG testng = new TestNG(); | ||
testng.setOutputDirectory(OutputDirectoryPatch.getOutputDirectory()); | ||
testng.setTestClasses(classesUnderTest); | ||
testng.addListener(tla); | ||
testng.setConfigFailurePolicy(XmlSuite.FailurePolicy.CONTINUE); | ||
testng.setGroups("group1"); | ||
testng.run(); | ||
verify(tla, 1, 0, 0); | ||
} | ||
|
||
@Test | ||
public void commandLineTest_policyAsSkip() { | ||
String[] argv = | ||
new String[] { | ||
"-log", | ||
"0", | ||
"-d", | ||
OutputDirectoryPatch.getOutputDirectory(), | ||
"-configfailurepolicy", | ||
"skip", | ||
"-testclass", | ||
ClassWithFailedBeforeMethodAndMultipleTests.class.getCanonicalName() | ||
}; | ||
TestListenerAdapter tla = new TestListenerAdapter(); | ||
TestNG.privateMain(argv, tla); | ||
|
||
verify(tla, 1, 1, 2); | ||
} | ||
|
||
@Test | ||
public void commandLineTest_policyAsContinue() { | ||
String[] argv = | ||
new String[] { | ||
"-log", | ||
"0", | ||
"-d", | ||
OutputDirectoryPatch.getOutputDirectory(), | ||
"-configfailurepolicy", | ||
"continue", | ||
"-testclass", | ||
ClassWithFailedBeforeMethodAndMultipleTests.class.getCanonicalName() | ||
}; | ||
TestListenerAdapter tla = new TestListenerAdapter(); | ||
TestNG.privateMain(argv, tla); | ||
|
||
verify(tla, 2, 0, 0); | ||
} | ||
|
||
@Test | ||
public void commandLineTestWithXMLFile_policyAsSkip() { | ||
String[] argv = | ||
new String[] { | ||
"-log", | ||
"0", | ||
"-d", | ||
OutputDirectoryPatch.getOutputDirectory(), | ||
"-configfailurepolicy", | ||
"skip", | ||
getPathToResource("testng-configfailure.xml") | ||
}; | ||
TestListenerAdapter tla = new TestListenerAdapter(); | ||
TestNG.privateMain(argv, tla); | ||
|
||
verify(tla, 1, 1, 2); | ||
} | ||
|
||
@Test | ||
public void commandLineTestWithXMLFile_policyAsContinue() { | ||
String[] argv = | ||
new String[] { | ||
"-log", | ||
"0", | ||
"-d", | ||
OutputDirectoryPatch.getOutputDirectory(), | ||
"-configfailurepolicy", | ||
"continue", | ||
getPathToResource("testng-configfailure.xml") | ||
}; | ||
TestListenerAdapter tla = new TestListenerAdapter(); | ||
TestNG.privateMain(argv, tla); | ||
|
||
verify(tla, 2, 0, 0); | ||
} | ||
|
||
private void verify( | ||
TestListenerAdapter tla, | ||
int configurationFailures, | ||
int configurationSkips, | ||
int skippedTests) { | ||
assertEquals( | ||
tla.getConfigurationFailures().size(), | ||
configurationFailures, | ||
"wrong number of configuration failures"); | ||
assertEquals( | ||
tla.getConfigurationSkips().size(), | ||
configurationSkips, | ||
"wrong number of configuration skips"); | ||
assertEquals(tla.getSkippedTests().size(), skippedTests, "wrong number of skipped tests"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ng-core/src/test/java/test/configurationfailurepolicy/issue2731/ConfigFailTestSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where I have a concern.
The documentation says this
Whether TestNG should continue to execute the remaining tests in the suite or skip them if an @Before* method fails. Default behavior is skip.
But here we are trying to move forward with trying to run the next lower level configuration even when the earlier higher order one failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, the default behavior is skip because of that the default config policy is set to
FailurePolicy DEFAULT_CONFIG_FAILURE_POLICY = FailurePolicy.SKIP;
, I'm not sure the description forContinue
, will look up in document.