Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip single test with maven with command line options

I would like to skip a single test (e.g. com.example.MyTest) when building a project with Maven from the command line.

I'm aware of similar questions like this one, but they all require either modification of source code or pom.xml. I would like to do without modifications. How can I exclude a test using command line options only?

What I've tried so far after reading some documentation is

mvn clean install -Dtest="*,!com.example.MyTest"

but the test is still not skipped. I'm using surefire plugin version 2.19 and JUnit 4.11.

like image 643
Mifeet Avatar asked Feb 09 '16 09:02

Mifeet


People also ask

How can you override skipTests parameter in command line?

Skipping by default by initializing the skipTests element value to true in properties and then overriding it through the command line by mentioning the value of -DskipTests in the maven phase/build execution command.

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”. As the output shows, only the test class we've passed to the test parameter is executed.


1 Answers

It turns out that (at least in Surefire 2.19), the test pattern doesn't work with fully qualified class names. So the right solution is

mvn clean install -Dtest="*,!MyTest"

i.e. without the package path.

In Surefire 2.19.1, it should be possible to use fully qualified names. In versions older than 2.19, neither seems to work.

like image 119
Mifeet Avatar answered Nov 02 '22 00:11

Mifeet