During development, you may run a single test class repeatedly. To run this through Maven, set the it.test property to a specific test case.
mvn -Dit.test=ITCircle verify
The value for the it.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 -Dit.test=ITCi*le verify
And you may use multiple names/patterns, separated by commas:
mvn -Dit.test=ITSquare,ITCi*le verify
NOTE: Use syntax e.g. "foo/MyTest.java", "**/MyTest.java", "MyTest" for "test" parameter (see includes/excludes) instead of fully qualified Java class names.
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. Use syntax e.g. "foo/MyTest.java", "**/MyTest.java", "MyTest" for "test" parameter (see includes/excludes) instead of fully qualified Java class names.
You must use the following syntax:
mvn -Dit.test=ITCircle#mytest verify
You can use patterns too
mvn -Dit.test=ITCircle#test* verify
Since of Failsafe Plugin 2.19 you can select multiple methods (JUnit 4, JUnit 4.7+ and TestNG):
mvn -Dit.test=ITCircle#testOne+testTwo verify
Note this feature was available in JUnit 4 provider only since of Failsafe Plugin 2.12.1.
As of Failsafe Plugin 2.19 multiple formats are supported in one pattern (JUnit 4, JUnit 4.7+, TestNG):
mvn "-Dit.test=???IT, !Unstable*, pkg/**/Ci*leIT.java, *IT#test*One+testTwo?????, #fast*+slowTest" verify mvn "-Dit.test=Basic*, !%regex[.*.Unstable.*], !%regex[.*.MyIT.class#one.*|two.*], %regex[#fast.*|slow.*]" verify
The exclamation mark (!) excludes tests. The character (?) within non-regex pattern replaces one character in file name or path. The file extensions are not mandatory in non-regex patterns, and packages with slash can be used. The regex validates fully qualified class file, and validates test methods separately after (#) however class is optional. The regex supports '.class' file extension only. Note the regex comments, marked by (#) character, are unsupported. The Parameterized JUnit runner describes test methods using an index in brackets, so the non-regex method pattern would become #testMethod[*]. If using the JUnit annotation @Parameters(name="{index}: fib({0})={1}") and selecting the index e.g. 5 in pattern, the non-regex method pattern would become #testMethod[5:*].