Using Maven, how do I run specific tests?

66,969

Solution 1

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.

Solution 2

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.

Share:
66,969
user84592
Author by

user84592

a mobile internet developer.

Updated on November 08, 2020

Comments

  • user84592
    user84592 about 2 years

    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?