Fix #834: Nested suites not supported by 'testnames'
diff --git a/src/main/java/org/testng/TestNG.java b/src/main/java/org/testng/TestNG.java
index 6cb522a..6becc09 100644
--- a/src/main/java/org/testng/TestNG.java
+++ b/src/main/java/org/testng/TestNG.java
@@ -416,6 +416,8 @@
* original suite.
*/
private static XmlSuite extractTestNames(XmlSuite s, List<String> testNames) {
+ extractTestNamesFromChildSuites(s, testNames);
+
List<XmlTest> tests = Lists.newArrayList();
for (XmlTest xt : s.getTests()) {
for (String tn : testNames) {
@@ -436,6 +438,18 @@
}
}
+ private static void extractTestNamesFromChildSuites(XmlSuite s, List<String> testNames) {
+ List<XmlSuite> childSuites = s.getChildSuites();
+ for (int i = 0; i < childSuites.size(); i++) {
+ XmlSuite child = childSuites.get(i);
+ XmlSuite extracted = extractTestNames(child, testNames);
+ // if a new xml suite is created, which means some tests was extracted, then we replace the child
+ if (extracted != child) {
+ childSuites.set(i, extracted);
+ }
+ }
+ }
+
/**
* Define the number of threads in the thread pool.
*/
@@ -981,13 +995,13 @@
private void checkSuiteNamesInternal(List<XmlSuite> suites, Set<String> names) {
for (XmlSuite suite : suites) {
final String name = suite.getName();
-
+
int count = 0;
String tmpName = name;
while (names.contains(tmpName)) {
tmpName = name + " (" + count++ + ")";
}
-
+
if (count > 0) {
suite.setName(tmpName);
names.add(tmpName);
@@ -1603,7 +1617,7 @@
result.suiteThreadPoolSize=(Integer) suiteThreadPoolSize;
}
}
-
+
configure(result);
}