Skip to content

Commit

Permalink
Restore testnames when using suites in suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Aldrin committed Jan 14, 2022
1 parent 55e8e52 commit 43f9b2e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,5 +1,6 @@
Current
7.6.0
Fixed: GITHUB-2709: Testnames not working together with suites in suite (Martin Aldrin)
Fixed: GITHUB-2637: Upgrade to JDK11 as the minimum JDK requirements(Krishnan Mahadevan)

7.5
Expand Down
6 changes: 5 additions & 1 deletion testng-core/src/main/java/org/testng/JarFileUtils.java
Expand Up @@ -95,7 +95,11 @@ private boolean testngXmlExistsInJar(File jarFile, List<String> classes) throws
TestNamesMatcher testNamesMatcher = new TestNamesMatcher(suite, testNames);
List<String> missMatchedTestname = testNamesMatcher.getMissMatchedTestNames();
if (!missMatchedTestname.isEmpty()) {
throw new TestNGException("The test(s) <" + missMatchedTestname + "> cannot be found.");
throw new TestNGException(
"The test(s) <"
+ missMatchedTestname
+ "> cannot be found in suite: "
+ suite.getName());
}
suites.addAll(testNamesMatcher.getSuitesMatchingTestNames());
} else {
Expand Down
6 changes: 4 additions & 2 deletions testng-core/src/main/java/org/testng/TestNG.java
Expand Up @@ -353,7 +353,8 @@ private Collection<XmlSuite> processCommandLineArgs(Collection<XmlSuite> allSuit
TestNamesMatcher testNamesMatcher = new TestNamesMatcher(s, m_testNames);
List<String> missMatchedTestname = testNamesMatcher.getMissMatchedTestNames();
if (!missMatchedTestname.isEmpty()) {
throw new TestNGException("The test(s) <" + missMatchedTestname + "> cannot be found.");
throw new TestNGException(
"The test(s) <" + missMatchedTestname + "> cannot be found, in suite: " + s.getName());
}
result.addAll(testNamesMatcher.getSuitesMatchingTestNames());
}
Expand Down Expand Up @@ -420,7 +421,8 @@ public void initializeSuitesAndJarFile() {
new JarFileUtils(getProcessor(), m_xmlPathInJar, m_testNames, m_parallelMode);

Collection<XmlSuite> allSuites = utils.extractSuitesFrom(jarFile);
m_suites.addAll(processCommandLineArgs(allSuites));
allSuites.forEach(this::processParallelModeCommandLineArgs);
m_suites.addAll(allSuites);
}

/** @param threadCount Define the number of threads in the thread pool. */
Expand Down
19 changes: 18 additions & 1 deletion testng-core/src/test/java/org/testng/JarFileUtilsTest.java
Expand Up @@ -12,6 +12,7 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import com.google.common.collect.Lists;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.jarfileutils.JarCreator;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void testWithNoTestNames() throws MalformedURLException {
@Test(
expectedExceptions = TestNGException.class,
expectedExceptionsMessageRegExp =
"\nThe test\\(s\\) <\\[testng-tests-child11\\]> cannot be found.")
"\nThe test\\(s\\) <\\[testng-tests-child11\\]> cannot be found in suite: testng-tests-suite")
public void testWithInvalidTestNames() throws MalformedURLException {
JarFileUtils utils = newJarFileUtils(Collections.singletonList("testng-tests-child11"));
runTest(
Expand All @@ -82,6 +83,22 @@ public void testWithInvalidXmlFile() throws MalformedURLException {
"Jar suite");
}

/**
* Test to ensure that exception is not thrown.
* Ensure that GITHUB-2709 can not happen again.
* @throws MalformedURLException
*/
@Test
public void ensureThatExceptionAreNotThrown() throws MalformedURLException {
TestNG testNg = new TestNG(false);
List<String> testNames = Lists.newArrayList("testng-tests-child2", "testng-tests-child4", "testng-tests-child5", "dummy");
testNg.setTestNames(testNames);
testNg.setXmlPathInJar(jar.getAbsolutePath());
testNg.setTestJar(jar.getAbsolutePath());
testNg.initializeSuitesAndJarFile();
Assert.assertEquals(testNg.m_suites.size(),1);
}

@Test
public void testWithValidTestNamesFromMultiChildSuites() throws MalformedURLException {
JarFileUtils utils =
Expand Down

0 comments on commit 43f9b2e

Please sign in to comment.