Run Junit Suite using Maven Command

Java SE picture Java SE · Aug 1, 2012 · Viewed 50.6k times · Source

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.

Answer

Java SE picture Java SE · Aug 2, 2012

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