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.
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”.
During development, you may run a single test class repeatedly. To run this through Maven, set the test property to a specific test case. The value for the test parameter is the name of the test class (without the extension; we'll strip off the extension if you accidentally provide one).
The simplest way to run integration tests is to use the Maven failsafe plugin. By default, the Maven surefire plugin executes unit tests during the test phase, while the failsafe plugin runs integration tests in the integration-test phase.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With