This post is older than a year. Consider some information might not be accurate anymore.
The Maven target test executes all tests under
src/test. This article assumes you are familiar with JUnit tests.
Maven comes with an option to skip the unit test,
-Dmaven.test.skip=true. If you absolutely must, you can also use the
maven.test.skipproperty to skip compiling the tests.
maven.test.skipis honored by Surefire, Failsafe and the Compiler Plugin.
mvn install -Dmaven.test.skip=true mvn package -Dmaven.test.skip=true
You can also skip the tests via command line by executing the following command:
mvn install -DskipTests
Skip integration tests
Since skipTests is also followed by the Surefire Plugin, this will have the effect of not running any tests. If, instead, you want to skip only the integration tests being run by the Failsafe Plugin, you would use the
mvn install -DskipITs
Running a Single Test
«During development, you may run a single test class repeatedly. To run this through Maven, set the test property to a specific test case.»http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html
mvn -Dtest=TestCircle test
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).
You may also use patterns to run a number of tests:
mvn -Dtest=TestCi*le test
And you may use multiple names/patterns, separated by commas:
mvn -Dtest=TestSquare,TestCi*le test
Running a Set of Methods in a Single Test Class
As of Surefire 2.7.3, you can also run only a subset of the tests in a test class. NOTE : This feature is supported only for Junit 4.x and TestNG. You must use the following syntax:
mvn -Dtest=TestCircle#mytest test
You can use patterns too
mvn -Dtest=TestCircle#test* test
As of Surefire 2.12.1, you can select multiple methods
mvn -Dtest=TestCircle#testOne+testTwo test