-
Notifications
You must be signed in to change notification settings - Fork 999
/
GroupSuiteTest.java
152 lines (125 loc) · 5.73 KB
/
GroupSuiteTest.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
146
147
148
149
150
151
152
package test.groupinvocation;
import com.google.common.base.Joiner;
import org.testng.ITestNGListener;
import org.testng.TestNG;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
import test.InvokedMethodNameListener;
import test.SimpleBaseTest;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test that <suite> tags can have g.
*/
public class GroupSuiteTest extends SimpleBaseTest {
private static final File PARENT = new File(getPathToResource("groupinvocation"));
@DataProvider
private static Object[][] dp() {
return new Object[][]{
{new String[]{"suiteA.xml", "suiteB.xml"}, /* Group in xml */ true},
{new String[]{"suiteA.xml", "suiteB.xml"}, /* Group in TestNG */ false},
{new String[]{"parent-suiteA.xml", "parent-suiteB.xml"}, /* Group in xml */ true},
{new String[]{"parent-suiteA.xml", "parent-suiteB.xml"}, /* Group in TestNG */ false},
{new String[0], /* Group in xml */ true},
{new String[0], /* Group in TestNG */ false}
};
}
@Test(dataProvider = "dp")
public void includeFromSuite0(String[] withSuiteFiles, boolean excludeWithXml) {
runWithSuite(withSuiteFiles, excludeWithXml, "a", "b", "c", "a2", "b2", "c2");
}
@Test(dataProvider = "dp")
public void includeFromSuite1(String[] withSuiteFiles, boolean excludeWithXml) {
runWithSuite(withSuiteFiles, excludeWithXml, g("a"), g(), "a", "a2");
}
@Test(dataProvider = "dp")
public void includeFromSuite2(String[] withSuiteFiles, boolean excludeWithXml) {
runWithSuite(withSuiteFiles, excludeWithXml, g("a", "b"), g(), "a", "b", "a2", "b2");
}
@Test(dataProvider = "dp")
public void excludeFromSuite1(String[] withSuiteFiles, boolean excludeWithXml) {
runWithSuite(withSuiteFiles, excludeWithXml, g(), g("a"), "b", "c", "b2", "c2");
}
@Test(dataProvider = "dp")
public void excludeFromSuite2(String[] withSuiteFiles, boolean excludeWithXml) {
runWithSuite(withSuiteFiles, excludeWithXml, g(), g("a", "b"), "c", "c2");
}
@Test(description = "Include in both suite and test")
public void includeTestAndSuite1Xml() {
runWithSuite(g("a"), g(), g("b"), g(), true, "a", "b", "a2", "b2");
}
@Test(description = "Include in both suite and test")
public void includeTestAndSuite1Cli() {
runWithSuite(g("a"), g(), g("b"), g(), false, "a", "b", "a2", "b2");
}
@Test(description = "Include in suite, exclude in test")
public void excludeTestAndSuite2Xml() {
runWithSuite(g("a", "b"), g(), g(), g("a"), true, "b", "b2");
}
@Test(description = "Include in suite, exclude in test")
public void excludeTestAndSuite2Cli() {
runWithSuite(g("a", "b"), g(), g(), g("a"), false, "b", "b2");
}
private void runWithSuite(String[] withSuiteFiles, boolean excludeWithXml, String... methods) {
runWithSuite(withSuiteFiles, excludeWithXml, g(), g(), g(), g(), methods);
}
private void runWithSuite(String[] withSuiteFiles, boolean excludeWithXml, List<String> suiteGroups, List<String> excludedSuiteGroups,
String... methods) {
runWithSuite(withSuiteFiles, excludeWithXml, suiteGroups, excludedSuiteGroups, g(), g(), methods);
}
private void runWithSuite(List<String> suiteGroups, List<String> excludedSuiteGroups,
List<String> testGroups, List<String> excludedTestGroups,
boolean groupsWithXml, String... methods) {
runWithSuite(new String[0], groupsWithXml, suiteGroups, excludedSuiteGroups, testGroups, excludedTestGroups, methods);
}
private void runWithSuite(String[] withSuiteFiles, boolean groupsWithXml, List<String> suiteGroups, List<String> excludedSuiteGroups,
List<String> testGroups, List<String> excludedTestGroups,
String... methods) {
TestNG tng = create();
XmlSuite suite = createXmlSuite("Groups");
if (groupsWithXml) {
suite.setIncludedGroups(suiteGroups);
suite.setExcludedGroups(excludedSuiteGroups);
} else {
tng.setGroups(Joiner.on(',').join(suiteGroups));
tng.setExcludedGroups(Joiner.on(',').join(excludedSuiteGroups));
}
if (withSuiteFiles.length != 0) {
List<String> suiteFiles = new ArrayList<>(withSuiteFiles.length);
for (String suiteFile : withSuiteFiles) {
suiteFiles.add(new File(PARENT, suiteFile).getAbsolutePath());
}
suite.setSuiteFiles(suiteFiles);
createXmlTest(suite, "Groups-test");
} else {
XmlTest test = createXmlTest(suite, "Groups-test", GroupSuiteSampleTest.class, GroupSuiteSampleTest2.class);
test.setIncludedGroups(testGroups);
test.setExcludedGroups(excludedTestGroups);
}
tng.setXmlSuites(Collections.singletonList(suite));
InvokedMethodNameListener listener = new InvokedMethodNameListener();
tng.addListener((ITestNGListener) listener);
tng.run();
assertThat(listener.getInvokedMethodNames()).containsExactly(methods);
}
@Test(description = "GITHUB-1574")
public void testToCheckNoConfigurationsAreExecuted() {
XmlSuite suite = createXmlSuite("suite");
XmlTest test = createXmlTest(suite, "test", Issue1574TestclassSample.class);
test.addExcludedGroup("sometest");
TestNG testng = create(suite);
InvokedMethodNameListener listener = new InvokedMethodNameListener();
testng.addListener((ITestNGListener) listener);
testng.run();
assertThat(listener.getInvokedMethodNames()).containsExactly("anothertest", "tearDownSuite");
}
private static List<String> g(String... groups) {
return Arrays.asList(groups);
}
}