Skip single test with maven with command line options
Asked Answered
P

1

13

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.

Perigon answered 9/2, 2016 at 9:25 Comment(0)
P
16

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.

Perigon answered 9/2, 2016 at 9:33 Comment(6)
It didn't work for me :( This is how I'm using it: ` test -Dlog4j.configuration=log4j-dm.xml -Dtest="*,!Testname1Test,!Testname2Test,!Testname3Test,!Testname4Test" `.Anesthesiology
What version of surefire are you using?Perigon
Version: [INFO] --- maven-surefire-plugin:2.12.4:test (default-test)Anesthesiology
I guess that your version of Surefire doesn't support excluding tests like this. Try upgrading to 2.19.Perigon
When I start Jenkins, it says the version is maven-surefire-plugin:2.12.4. I already updated the pom version my app, but I don't know how to do that in Jenkins. I'm still searching how to do that.Anesthesiology
I had to escape the "!" (use "\!" instead) otherwise I get a bash "event not found" error, see serverfault.com/questions/208265/what-is-bash-event-not-foundAlanaalanah

© 2022 - 2024 — McMap. All rights reserved.