forked from testng-team/testng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FailurePolicyTest.java
145 lines (130 loc) · 4.88 KB
/
FailurePolicyTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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 FailurePolicyTest {
// 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.SKIP);
}
@DataProvider(name = "dp")
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[] {ClassWithFailedBeforeClassMethodAndBeforeMethodAfterMethodAfterClass.class},
1,
3,
1
},
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[] {
ClassWithFailedBeforeClassMethod.class, ExtendsClassWithFailedBeforeClassMethod.class
},
2,
3,
3
},
new Object[] {new Class[] {ClassWithSkippingBeforeMethod.class}, 0, 1, 1},
new Object[] {new Class[] {FactoryClassWithFailedBeforeMethod.class}, 2, 0, 2},
new Object[] {
new Class[] {FactoryClassWithFailedBeforeMethodAndMultipleInvocations.class}, 8, 0, 8
},
new Object[] {new Class[] {FactoryClassWithFailedBeforeClassMethod.class}, 2, 2, 2},
};
}
@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.SKIP);
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.SKIP);
testng.setGroups("group1");
testng.run();
verify(tla, 1, 3, 1);
}
@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 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);
}
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");
}
}