Search code examples
maventestngmaven-profiles

How to run particular suiteXmlFile from maven profile


My maven profile looks like below and it has both smoke and regression XML but I want to run only smoke or regression how to do this?

<profile>
        <id>smoke</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>src/test/resources/smoke.xml</suiteXmlFile>
                            <suiteXmlFile>src/test/resources/regression.xml</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

Solution

  • Regardless of whatever you have in your pom under <suiteXmlFiles> you can override that by specifying it for running from cmd or your CI:

    For running smoke only:

     mvn test -Dsurefire.suiteXmlFiles=src/test/resources/smoke.xml
    

    For running regression only:

    mvn test -Dsurefire.suiteXmlFiles=src/test/resources/regression.xml
    

    For running both:

    mvn test -Dsurefire.suiteXmlFiles=src/test/resources/smoke.xml,src/test/resources/regression.xml
    

    Another option, as you already using profiles - to create three different profiles: smoke, regression, and general and provide the required one before run.