简体   繁体   English

使用命令行选项使用maven跳过单个测试

[英]Skip single test with maven with command line options

I would like to skip a single test (eg com.example.MyTest ) when building a project with Maven from the command line. 我想从命令行使用Maven构建项目时跳过单个测试(例如com.example.MyTest )。

I'm aware of similar questions like this one , but they all require either modification of source code or pom.xml . 我知道像类似的问题这一个 ,但它们都需要的源代码或任何修改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 . 我正在使用surefire插件版本2.19和JUnit 4.11

It turns out that (at least in Surefire 2.19), the test pattern doesn't work with fully qualified class names. 事实证明(至少在Surefire 2.19中),测试模式不适用于完全限定的类名。 So the right solution is 所以正确的解决方案是

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

ie without the package path. 即没有包路径。

In Surefire 2.19.1, it should be possible to use fully qualified names. 在Surefire 2.19.1中, 应该可以使用完全限定名称。 In versions older than 2.19, neither seems to work. 在2.19之前的版本中,似乎都不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM