-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
configfailurepolicy=continue only works for BeforeTest when using Tes…
…tNG XML file Fixes #2731
- Loading branch information
Showing
9 changed files
with
235 additions
and
46 deletions.
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