akash
akash

Reputation: 11

Unable to run multiple testng xml files using maven

My project has two testNG xml files, TestNG.xml and TestNG2.xml,both are in the root folder. I have made the maven pom configurations as below but when i run , the file "TestNG.xml" runs twice and TestNG2.xml is left untouched.

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <configuration>
                <suiteXmlFiles>
                    <file>TestNG2.xml</file>
                    <file>TestNG.xml</file>
                </suiteXmlFiles>
                <properties>
                    <property>
                        <name>suitethreadpoolsize</name>
                        <value>2</value>
                    </property>
                </properties>
            </configuration>
        </plugin>

I have tried running from cmd also but again only TestNG.xml is run twice.

mvn clean test -Dsurefire.suiteXmlFiles=TestNG2.xml,TestNG.xml

How can i run both the files in same run ?

Upvotes: 1

Views: 4789

Answers (2)

user21088962
user21088962

Reputation: 1

Do your TestNG2.xml and TestNG.xml have the same suite name tag? They should be different. E.g: suite name="Suite" in TestNG.xml and suite name="Suite2" in TestNG2.xml

Upvotes: 0

Manmohan_singh
Manmohan_singh

Reputation: 1804

You are not using the correct tags . You have to refactor the tagnames inside the suiteXmlFiles block. The pom file should look like this:-

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.21.0</version>
    <configuration>
        <suiteXmlFiles>
            <suiteXmlFile>TestNG2.xml</suiteXmlFile>
            <suiteXmlFile>TestNG.xml</suiteXmlFile>
        </suiteXmlFiles>
        <properties>
            <property>
                <name>suitethreadpoolsize</name>
                <value>2</value>
            </property>
        </properties>
    </configuration>
</plugin>

And just in case , if you want to dynamically run different testNG.xml from command prompt , then just add a placeholder variable pom file. The value to this placeholder is passed in command prompt using -D switch. The pom file in that case shall look like this:-

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.21.0</version>
        <configuration>
            <suiteXmlFiles>
                <suiteXmlFile>${testSuite}.xml</suiteXmlFile>

            </suiteXmlFiles>
            <properties>
                <property>
                    <name>suitethreadpoolsize</name>
                    <value>2</value>
                </property>
            </properties>
        </configuration>
    </plugin>

The command to pass test suite shall be :

 mvn clean integration-test -DtestSuite=testNG

Upvotes: 1

Related Questions