Run a specific test with Apache Maven

Published on 07/07/2023

Problem 1

How can I execute a specific test class using Maven ?

Solution

Using the option -Dtest= followed by the simple test class name.

mvn test -Dtest=MyTestClass

Problem 2

And if I want to run only a specific test case of the class ?

Solution

Follow the test class name with a # and the method name

mvn test -Dtest=MyTestClass#myMethodName
  • Article is published under CC-BY 4.0
  • If not explicitly declared code snippets are published under MIT license