Skip to content

Commit

Permalink
Merge pull request #2712 from martinaldrin/testnames
Browse files Browse the repository at this point in the history
Restore testnames when using suites in suite.
  • Loading branch information
juherr committed Jan 17, 2022
2 parents 55e8e52 + 5273e25 commit 2091b13
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 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
5 changes: 1 addition & 4 deletions testng-core/src/main/java/org/testng/JarFileUtils.java
Expand Up @@ -93,10 +93,7 @@ private boolean testngXmlExistsInJar(File jarFile, List<String> classes) throws
// If test names were specified, only run these test names
if (testNames != null) {
TestNamesMatcher testNamesMatcher = new TestNamesMatcher(suite, testNames);
List<String> missMatchedTestname = testNamesMatcher.getMissMatchedTestNames();
if (!missMatchedTestname.isEmpty()) {
throw new TestNGException("The test(s) <" + missMatchedTestname + "> cannot be found.");
}
testNamesMatcher.validateMissMatchedTestNames();
suites.addAll(testNamesMatcher.getSuitesMatchingTestNames());
} else {
suites.add(suite);
Expand Down
8 changes: 3 additions & 5 deletions testng-core/src/main/java/org/testng/TestNG.java
Expand Up @@ -351,10 +351,7 @@ private Collection<XmlSuite> processCommandLineArgs(Collection<XmlSuite> allSuit
}
// If test names were specified, only run these test names
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.");
}
testNamesMatcher.validateMissMatchedTestNames();
result.addAll(testNamesMatcher.getSuitesMatchingTestNames());
}

Expand Down Expand Up @@ -420,7 +417,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
Expand Up @@ -43,11 +43,13 @@ public List<XmlSuite> getSuitesMatchingTestNames() {
return cloneSuites;
}

public List<String> getMissMatchedTestNames() {
public void validateMissMatchedTestNames() {
List<String> tmpTestNames = Lists.newArrayList();
tmpTestNames.addAll(testNames);
tmpTestNames.removeIf(matchedTestNames::contains);
return tmpTestNames;
if (!tmpTestNames.isEmpty()) {
throw new TestNGException("The test(s) <" + tmpTestNames + "> cannot be found in suite.");
}
}

public List<XmlTest> getMatchedTests() {
Expand Down
19 changes: 18 additions & 1 deletion testng-core/src/test/java/org/testng/JarFileUtilsTest.java
Expand Up @@ -55,7 +55,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.")
public void testWithInvalidTestNames() throws MalformedURLException {
JarFileUtils utils = newJarFileUtils(Collections.singletonList("testng-tests-child11"));
runTest(
Expand All @@ -82,6 +82,23 @@ 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 =
Arrays.asList("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 2091b13

Please sign in to comment.