diff --git a/CHANGES.txt b/CHANGES.txt index 45b2265678..e12be724ec 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,6 @@ Current +Fixed: GITHUB-581: Parameters of nested test suites are overridden(Krishnan Mahadevan) Fixed: GITHUB-727 : Fixing data races (Krishnan Mahadevan) Fixed: GITHUB-2913: Maps containing nulls can be incorrectly considered equal (Alex Heneveld) diff --git a/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java b/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java index 89a9308e69..249fbf9e09 100644 --- a/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java +++ b/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java @@ -101,6 +101,7 @@ enum Location { } private final Stack m_locations = new Stack<>(); + private boolean isSuiteFileTag = false; private XmlClass m_currentClass = null; private ArrayList m_currentIncludedMethods = null; @@ -196,9 +197,11 @@ private void xmlSuiteFile(boolean start, Attributes attributes) { String path = attributes.getValue("path"); pushLocation(Location.SUITE); m_suiteFiles.add(path); + isSuiteFileTag = true; } else { m_currentSuite.setSuiteFiles(m_suiteFiles); popLocation(); + isSuiteFileTag = false; } } @@ -611,6 +614,13 @@ public void startElement(String uri, String localName, String qName, Attributes } else if ("exclude".equals(qName)) { xmlExclude(true, attributes); } else if ("parameter".equals(qName)) { + if (isSuiteFileTag) { + // do-not process a tag when it is specified inside + Logger.getLogger(getClass()) + .warn( + "Ignoring the tag because it is specified inside a tag."); + return; + } String value = expandValue(attributes.getValue("value")); Location location = m_locations.peek(); switch (location) { diff --git a/testng-core/src/test/java/test/parameters/ParameterTest.java b/testng-core/src/test/java/test/parameters/ParameterTest.java index 44c2ec93a8..8f43d40036 100644 --- a/testng-core/src/test/java/test/parameters/ParameterTest.java +++ b/testng-core/src/test/java/test/parameters/ParameterTest.java @@ -2,9 +2,12 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.testng.ISuite; +import org.testng.ISuiteListener; import org.testng.ITestResult; import org.testng.TestListenerAdapter; import org.testng.TestNG; @@ -131,4 +134,21 @@ public void testNativeInjectionAndParamsInjection() { testng.run(); assertThat(listener.getPassedTests().isEmpty()).isFalse(); } + + @Test(description = "GITHUB-581") + public void ensureParametersSpecifiedInsideSuiteFilesTagAreIgnored() { + TestNG testng = create(); + testng.setTestSuites( + Collections.singletonList("src/test/resources/parametertest/issue_581/parent_suite.xml")); + Map> actualParameters = new HashMap<>(); + testng.addListener( + new ISuiteListener() { + @Override + public void onStart(ISuite suite) { + actualParameters.put(suite.getName(), suite.getXmlSuite().getAllParameters()); + } + }); + testng.run(); + actualParameters.values().forEach(each -> assertThat(each).isEmpty()); + } } diff --git a/testng-core/src/test/java/test/parameters/issue581/TestClassSample.java b/testng-core/src/test/java/test/parameters/issue581/TestClassSample.java new file mode 100644 index 0000000000..fb21ec245f --- /dev/null +++ b/testng-core/src/test/java/test/parameters/issue581/TestClassSample.java @@ -0,0 +1,12 @@ +package test.parameters.issue581; + +import org.testng.annotations.Optional; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +public class TestClassSample { + + @Parameters(value = "url") + @Test + public void test(@Optional String ignored) {} +} diff --git a/testng-core/src/test/resources/parametertest/issue_581/parent_suite.xml b/testng-core/src/test/resources/parametertest/issue_581/parent_suite.xml new file mode 100644 index 0000000000..268285ba28 --- /dev/null +++ b/testng-core/src/test/resources/parametertest/issue_581/parent_suite.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/testng-core/src/test/resources/parametertest/issue_581/suite_one.xml b/testng-core/src/test/resources/parametertest/issue_581/suite_one.xml new file mode 100644 index 0000000000..e8a1c79820 --- /dev/null +++ b/testng-core/src/test/resources/parametertest/issue_581/suite_one.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/testng-core/src/test/resources/parametertest/issue_581/suite_two.xml b/testng-core/src/test/resources/parametertest/issue_581/suite_two.xml new file mode 100644 index 0000000000..d584d6cbdb --- /dev/null +++ b/testng-core/src/test/resources/parametertest/issue_581/suite_two.xml @@ -0,0 +1,8 @@ + + + + + + + +