Search code examples
mavenmaven-2junittest-suite

Run Junit Suite using Maven Command


I have multiple Junit test suites (SlowTestSuite, FastTestSuite etc). I would like to run only specific suite using maven command. e.g.

mvn clean install test -Dtest=FastTestSuite -DfailIfNoTests=false

but its not working. Just not running any test at all. Any suggestions please.


Solution

  • I have achieved this by adding property into pom as:

    <properties>
        <runSuite>**/FastTestSuite.class</runSuite>
    </properties>
    

    and maven-surefire-plugin should be:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>${runSuite}</include>
                    </includes>
                </configuration>
            </plugin>
    

    so it means by default it will run FastTestSuite but you can run other test e.g. SlowTestSuite using maven command as:

    mvn install -DrunSuite=**/SlowTestSuite.class -DfailIfNoTests=false