Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Maven, how do I run specific tests?

I have thousands of unit tests in my project, and I'd like to choose one or a couple of them to run from the command line. What's the command to do that?

like image 527
user84592 Avatar asked Sep 27 '11 11:09

user84592


People also ask

How do I run a specific test in Maven?

The Maven surefire plugin provides a test parameter that we can use to specify test classes or methods we want to execute. If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”.


2 Answers

You can run all the tests in a class, by passing the -Dtest=<class> flag to Maven:

mvn clean test -Dtest=xxxxTest 

Since Surefire 2.8, you can also run an individual test, say a method testA within your unit tests, using the same flag:

mvn clean test -Dtest=xxxxTest#testA 

More examples for running multiple tests, by name pattern or name lists, can be found in the Maven Surefire documentation > Running a Single Test.

like image 59
Vineet Reynolds Avatar answered Sep 24 '22 13:09

Vineet Reynolds


Please read this piece of the maven surefire plugin manual. Basically you can do the following:

mvn -Dtest=*PerformanceTest clean test  

Which only runs all the test classes ending in PerformanceTest.

like image 27
Hiery Nomus Avatar answered Sep 25 '22 13:09

Hiery Nomus