I would like to skip only a single test while launching mvn install
.
Is there a way to do that ?
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”.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With