Skip to content

Same xmlsuite is added multiple times when tests are run using TestNG.SetXmlSuites method #863

Open
@virenv

Description

@virenv

@cbeust,

Here is the description of the problem.

My trimmed down run engine code

    Parser parser = new Parser(".\\CompleteSuite.xml");
    List<XmlSuite> xmlSuite = null;
    try {
        xmlSuite = parser.parseToList();
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // List<String> suites = new ArrayList<String>();
    TestNG testng = new TestNG();
    TestListener listner = new TestListener();
    testng.addListener(listner);
    testng.addListener(new SuiteListner());
    // suites.add(".\\CompleteSuite.xml");
    testng.setXmlSuites(xmlSuite);
    // testng.setTestSuites(suites);
    testng.setParallel("parallel");
    testng.setSuiteThreadPoolSize(5);
    testng.setDataProviderThreadCount(5);
    testng.setOutputDirectory("path to output");
    testng.run();

My suite XML looks like this

<suite name="suite of suites">
    <suite-files>
        <suite-file path="TestNG.xml" />
        <suite-file path="TestNG2.xml" />
    </suite-files>
</suite>

you can have any two testNG suites as mentioned here.

Problem
When you run this code you will get an exception stating
Two suites cannot have the same name: Suite2

This exception will come even if you have two different suite names. The reason is because of this code in initializeSuitesAndJarFile of TestNG class

    for (String suiteFile : s.getSuiteFiles()) {
        try {
            Collection<XmlSuite> childSuites = getParser(suiteFile).parse();
            for (XmlSuite cSuite : childSuites){
                cSuite.setParentSuite(s);
                s.getChildSuites().add(cSuite);
            }
        }

here do we really need adding of same suite back to the parent? s.getChildSuites().add(cSuite);

Virender

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions