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.
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.