unit-testingmavencontinuous-integration

maven :: run only single test in multi-module project


Is there any way to provide some command-line argument in order to skip all tests but one on some module? So I will not need to change pom.xml every time I will need to run another test?

For example, I want to create build configuration on TeamCity, and provide command-line arguments to run only single test in some module. Next time I will need to change it and run another test, and so on.

Perhaps it is not how CI is intended to be used, but still.


Solution

  • I assume you've read the docs about running a single test under surefire? What they don't tell you is how to do that in a sub-module:

    mvn test -Dtest=testname -pl subproject -am -Dsurefire.failIfNoSpecifiedTests=false
    

    Where subproject is the project containing that test. From the mvn man page:

    -pl,--projects arg Comma-delimited list of specified reactor projects to build instead of all projects. A project can be specified by [groupId]:artifactId or by its relative path.

    -am,--also-make If project list is specified, also build projects required by the list

    -Dsurefire.failIfNoSpecifiedTests=false has to be used with -am, otherwise Maven will still try to run tests within other modules (that are being also-made)

    OR

    -DfailIfNoTests=false if you are not using Surefire as a tests runner