Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore testnames when using suites in suite. #2712

Merged
merged 1 commit into from Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martinaldrin - I dont see any assertions. Was that intentional ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, The purpose of the test is to ensure that a exception is not thrown. I can not add any assert methods.
We just ensure that the method do not check suites in jarfiles here, because that is handled later in JarFileUtiles.
And JarFileUtiles already have unit tests to ensure that this is working as expected, the problem started to aggregate suites in the jarfile here without consider sub suites.

A very similar method exist in class: JarFileUtil method: testngXmlExistsInJar that take care of that part.

Assert.assertEquals(testNg.m_suites.size(), 1);
}

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