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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 22:19:37  来源:igfitidea点击:

Skip test case execution in maven doesn't even compile Test cases

javaeclipseunit-testingmaven

提问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 -DskipTestsit just skips execution of tests

当您指定-DskipTests它只是跳过测试的执行时,它会编译测试类

maven.test.skipstops compilation of test classes

maven.test.skip停止编译测试类



Documentation

文档

回答by Mureinik

-Dmaven.test.skip=trueis designed not to even compile the unit tests. If you want to build them but not run them, you could use the skipTestsflag:

-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 falsewhen not explicitelly specified.

请注意,这些属性false在未明确指定时默认为。

回答by Amit

<properties>
    <maven.test.skip>true</maven.test.skip>
</properties>

Add this code in your pom.xmlfile.

将此代码添加到您的pom.xml文件中。