Search code examples
javamavenunit-testingmaven-2maven-3

Run a single test method with maven


I know you can run all the tests in a certain class using:

mvn test -Dtest=classname

But I want to run an individual method and -Dtest=classname.methodname doesn't seem to work.


Solution

  • To run a single test method in Maven, you need to provide the command as:

    mvn test -Dtest=TestCircle#xyz test
    

    where TestCircle is the test class name and xyz is the test method.

    Wild card characters also work; both in the method name and class name.

    If you're testing in a multi-module project, specify the module that the test is in with -pl <module-name>.

    For integration tests use it.test=... option instead of test=...:

    mvn -pl <module-name> -Dit.test=TestCircle#xyz integration-test