Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 671
BillMan Avatar asked Dec 09 '09 13:12

BillMan


People also ask

How do I run a single Maven test?

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”.

How do you run a single test case?

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).

How do I run a specific integration test in Maven?

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.


1 Answers

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 
like image 173
Mudit Srivastava Avatar answered Sep 27 '22 21:09

Mudit Srivastava