Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 478
paulgreg Avatar asked May 07 '09 16:05

paulgreg


People also ask

How do I run a specific test in Maven?

The Maven surefire plugin provides a test parameter that we can use to specify test classes or methods we want to execute. If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”.

How do you skip a test in Java?

If you want to ignore a test method, use @Ignore along with @Test annotation. If you want to ignore all the tests of class, use @Ignore annotation at the class level.

How do I skip a test in Maven?

To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.


2 Answers

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 
like image 71
haridsv Avatar answered Oct 05 '22 13:10

haridsv


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.

like image 21
Steve Reed Avatar answered Oct 05 '22 12:10

Steve Reed