Shaun Abram
Technology and Leadership Blog
Running an individual unit test with maven
Individual tests can be run from maven. This must be done from within the folder that contains the source (as in the folder that contains src/test/java), which will likely be either be the root of your maven project, or in one of your modules.
For surefire (unit tests), to run a whole test class, this will be something like:
mvn -Dtest=com.your.package.YourTest test
or, to run a specific test method:
mvn -Dtest=com.your.package.YourTest#testMethod test
For failsafe (integration tests), it will be something like:
mvn -Dit.test=com.your.package.YourIT verify
This is covered in the maven surefire plugin docs and maven failesafe plugin docs respectively, but those examples don’t mention packages names, which are required.
Tags: failsafe, integrationtesting, JUnit, Maven, mvn, surefire, Testing, unittesting