Skip single test with maven with command line options

纵然是瞬间 提交于 2021-02-18 05:10:17

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/35288189/skip-single-test-with-maven-with-command-line-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!