Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 658
jdevelop Avatar asked Aug 08 '12 17:08

jdevelop


People also ask

How do you run a single unit test in Maven?

If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”. For instance, we can pass -Dtest=”TheFirstUnitTest” to the mvn command to execute the TheFirstUnitTest class only: $ mvn test -Dtest="TheFirstUnitTest" ...

Which command of Maven is used to run all unit tests?

We can run our unit tests with Maven by using the command: mvn clean test. When we run this command at command prompt, we should see that the Maven Surefire Plugin runs our unit tests. We can now create a Maven project that compiles and runs unit tests which use JUnit 5.


1 Answers

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 

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.

like image 69
Nick Gerner Avatar answered Nov 05 '22 23:11

Nick Gerner