For the tests in your project to work, certain settings are necessary. Here are some guidelines for avoiding basic mistakes.
1. Default configuration
By default Maven uses the following naming conventions when looking for tests to run:
- **/Test*.java
- **/*Test.java
- **/*Tests.java
- **/*TestCase.java
2. Specify names of tests in the command line
- Running a Single Test
1 |
mvn -Dtest=TestCircle 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. Use syntax e.g. “foo/MyTest.java”, “**/MyTest.java”, “MyTest” for “test” parameter .
You should use the following syntax:
1 |
mvn -Dtest=TestCircle#mytest test |
You can use patterns too
1 |
mvn -Dtest=TestCircle#test* test |
Since of Surefire Plugin 2.19 you can select multiple methods (JUnit 4, JUnit 4.7+ and TestNG):
1 |
mvn -Dtest=TestCircle#testOne+testTwo test |
- Multiple Formats in One
As of Surefire Plugin 2.19 multiple formats are supported in one pattern (JUnit 4, JUnit 4.7+, TestNG):
1 2 |
mvn "-Dtest=???Test, !Unstable*, pkg/**/Ci*leTest.java, *Test#test*One+testTwo?????, #fast*+slowTest" test mvn "-Dtest=Basic*, !%regex[.*.Unstable.*], !%regex[.*.MyTest.class#one.*|two.*], %regex[#fast.*|slow.*]" test |