Java 在 maven 中跳过测试用例执行甚至不编译测试用例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23380808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Skip test case execution in maven doesn't even compile Test cases
提问by sakura
Using Maven build configuration, we can configure it to skip test execution while building the source file. In eclipse we can check the checkbox labeled as 'Skip Test` and from command line we can use
使用 Maven 构建配置,我们可以将其配置为在构建源文件时跳过测试执行。在 eclipse 中,我们可以选中标记为“Skip Test”的复选框,然后从命令行我们可以使用
mvn clean install -Dmaven.test.skip=true
The Skip test doesn't even compile the unit test source codes.
跳过测试甚至不编译单元测试源代码。
Is there any way to configure maven such that it will compile the unit test classes but doesn't execute it?
有什么方法可以配置 maven 使其编译单元测试类但不执行它?
采纳答案by Jigar Joshi
It compiles test classes when you specify -DskipTests
it just skips execution of tests
当您指定-DskipTests
它只是跳过测试的执行时,它会编译测试类
maven.test.skip
stops compilation of test classes
maven.test.skip
停止编译测试类
Documentation
文档
回答by Mureinik
-Dmaven.test.skip=true
is designed not to even compile the unit tests. If you want to build them but not run them, you could use the skipTests
flag:
-Dmaven.test.skip=true
旨在甚至不编译单元测试。如果您想构建它们但不想运行它们,您可以使用以下skipTests
标志:
mvn clean install -DskipTests=true
or in its shorthand version:
或其速记版本:
mvn clean install -DskipTests
See also maven's documentation on skipping testsfor the full details.
有关完整详细信息,另请参阅 maven 的有关跳过测试的文档。
回答by tmarwen
When runnig a mvn install
, you can either:
运行 a 时mvn install
,您可以:
- Skip tests excution and compilation:
-Dmaven.test.skip=true
- Skip only tests execution but compile them:
-DskipTests=true
- 跳过测试执行和编译:
-Dmaven.test.skip=true
- 只跳过测试执行但编译它们:
-DskipTests=true
Note that those properties defaults to false
when not explicitelly specified.
请注意,这些属性false
在未明确指定时默认为。
回答by Amit
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
Add this code in your pom.xml
file.
将此代码添加到您的pom.xml
文件中。