Run JUnit Tests contained in dependency jar using Maven Surefire

There is a way of running a test in maven from another jar.
from maven-surefire-plugin version 2.15 you can tell maven to scan your test jars for tests and run them.
You don’t need to extract the tests jar.
Just add a dependency to your test jar and:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <dependenciesToScan>
                <dependency>test.jar.group:test.jar.artifact.id</dependency>
            </dependenciesToScan>
        </configuration>
    </plugin>

Took this stuff from https://gist.github.com/aslakknutsen/4520226
And https://issues.apache.org/jira/browse/SUREFIRE-569

As expected, this works for JUnit and Testng. Will probably work for anything that surefire can run.

Leave a Comment