Is there a way to skip only a single test in maven?

I would like to skip only a single test while launching mvn install.

Is there a way to do that ?


Solution 1:

You can specify an exclusion pattern to -Dtest option by prefixing it with an ! (exclamation mark). E.g.,

mvn -Dtest=\!FlakyTest* install

Found it in here and verified to be working. E.g., I was able to skip this flaky Jenkins test by using:

mvn -Dtest=\!CronTabTest* package

Solution 2:

With junit 4, I add an @Ignore annotation when I want to do that. This would work for you, unless you want to only sometimes ignore the test, or only ignore it when the build runs from maven. If this is the case, then I would ask "Why?"

Tests should be consistent, they should be portable, and they should always pass. If a specific test is problematic I would consider re-writing it, removing it entirely, or moving it to a different test suite or project.