Maven跳过测试

参考

http://maven.apache.org/plugins/maven-resources-plugin/testResources-mojo.html

http://maven.apache.org/plugins/maven-compiler-plugin/testCompile-mojo.html

http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html

boolean - Set this to "true" to bypass unit tests entirely. Its use is NOT RECOMMENDED, especially if you enable it using the "maven.test.skip" property, because maven.test.skip disables both running the tests and compiling the tests. Consider using the skipTests parameter instead. Default value is: false. User property is: maven.test.skip.
boolean 2.4 Set this to "true" to skip running tests, but still compile them. Its use is NOT RECOMMENDED, but quite convenient on occasion. Failsafe plugin deprecated the parameter skipTests and the parameter will be removed in Failsafe 3.0.0 as it is a source of conflicts between Failsafe and Surefire plugin. Default value is: false. User property is: skipTests.

环境

E:\mozq\demo_project\shiro>mvn -v
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: D:\tools\maven\apache-maven-3.6.1\bin\..
Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: D:\tools\jdk\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

案例一 跳过运行测试和编译测试

配置

<maven.test.skip>true</maven.test.skip> 跳过运行测试,测试资源,测试代码编译

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<!--
这个属性被3个插件使用,跳过testResources,testCompile,test。不处理测试,会快一点。
maven-resources-plugin:3.1.0:testResources
maven-compiler-plugin:3.8.1:testCompile
maven-surefire-plugin:2.22.2:test
-->
<maven.test.skip>true</maven.test.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

运行结果

[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ http_01 ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ http_01 ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ http_01 ---
[INFO] Tests are skipped.

案例二 只跳过运行测试

配置

<skipTests>true</skipTests> 只跳过运行测试,不跳过测试资源和测试代码编译。

<properties>
<skipTests>true</skipTests>
<!--<maven.test.skip>true</maven.test.skip>-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>6</maven.compiler.source>
<maven.compiler.target>6</maven.compiler.target>
<spring.version>4.3.2.RELEASE</spring.version>
<mybatis.version>3.2.6</mybatis.version>
</properties>
<build>
<!-- 资源文件 -->
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources> <!-- 插件jetty tomcat -->
<plugins>
<!-- 配置jetty运行方式 -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.0.M2</version>
<configuration>
<webAppConfig>
<contextPath>/xinhekqsys</contextPath>
</webAppConfig>
<httpConnector>
<port>8081</port>
<idleTimeout>10000</idleTimeout>
</httpConnector>
</configuration>
</plugin> <!-- maven项目在tomcat下运行的配制文件 -->
<!-- 配置tomcat运行方式 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- 注意tomcat7此处的url -->
<url>http://localhost:8080/manager/text</url>
<!-- 此处的名字必须和setting.xml中配置的ID一致 -->
<server>tomcat</server>
<!-- 此处的名字是项目发布的工程名 -->
<path>/xinhekqsys</path>
</configuration>
</plugin>
<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId>
<version>2.4</version> <configuration> <webResources> <resource> <directory>src/main/webapp/WEB-INF</directory>
</resource> </webResources> </configuration> </plugin> --> <plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId>
<version>2.4</version> <configuration> <webResources> <resource> <directory>src/main/webapp/WEB-INF</directory>
<directory>src/main/webapp</directory> </resource> </webResources> </configuration>
</plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
<compilerArguments>
<verbose /> <bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin> </plugins>
<!-- 最终项目打包包名 -->
<finalName>handordering</finalName>
</build>

运行结果

<skipTests>true</skipTests>
# 没有跳过测试资源
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ handordering ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\mozq\02 project\handordering\src\test\resources
[INFO]
# 没有跳过测试代码编译
[INFO] --- maven-compiler-plugin:3.6.0:testCompile (default-testCompile) @ handordering ---
[INFO] No sources to compile
[INFO]
# 跳过了运行测试
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ handordering ---
[INFO] Tests are skipped.
<maven.test.skip>true</maven.test.skip>
# 跳过了测试资源
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ handordering ---
[INFO] Not copying test resources
[INFO]
# 跳过了测试代码编译
[INFO] --- maven-compiler-plugin:3.6.0:testCompile (default-testCompile) @ handordering ---
[INFO] Not compiling test sources
[INFO] No sources to compile
[INFO]
# 跳过了运行测试
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ handordering ---
[INFO] Tests are skipped.

案例三 插件中配置跳过

插件和用户属性中同时对是否跳过测试进行配置,会以插件中为准。但是当跳过了测试资源和测试代码编译,又设置不跳过运行测试没有意义,因为此时不会生成测试代码。

配置

<properties>
<!-- 配置了跳过测试用户属性 -->
<maven.test.skip>true</maven.test.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- 插件中配置不跳过运行测试,以插件中配置为准。
当跳过了测试资源和测试代码编译,又设置不跳过运行测试没有意义,因为此时不会有测试代码来运行。
-->
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>

运行结果

# 跳过了测试资源
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ http_01 ---
[INFO] Not copying test resources
# 跳过了测试代码编译
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ http_01 ---
[INFO] Not compiling test sources
# 没有跳过运行测试,但是因为没有编译的测试代码,打印了没有测试需要运行。
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ http_01 ---
[INFO] No tests to run.

Maven跳过测试的更多相关文章

  1. maven 跳过测试 打包 及上传命令

    [main] ERROR org.apache.maven.cli.MavenCli - Failed to execute goal org.apache.maven.plugins:maven-s ...

  2. Maven 跳过测试目录

    在命令行使用 mvn install -Dmaven.skipTests 或 mvn install -Dmaven.test.skip=true 或在pom.xml设置 <build> ...

  3. maven跳过测试打包

    1.在执行run as时候加上参数: clean install compile -Dmaven.test.skip=true   2.在pom文件中添加如下: <plugins> < ...

  4. maven跳过测试编译命令

    mvn clean install/package/deploy -Dmaven.test.skip=true

  5. maven install 跳过 测试 test

    你可能想要配置 Maven 使其完全跳过单元测试. 可能你有一个很大的系统,单元测试需要花好多分钟来完成,而你不想在生成最终输出前等单元测试完成. 你可能正工作在一个遗留系统上面,这个系统有一系列的失 ...

  6. Maven配置插件跳过测试代码的编译和运行

    Maven配置插件跳过测试代码的编译和运行: <!-- 编译插件 --> <plugin> <groupId>org.apache.maven.plugins< ...

  7. maven打包如何跳过测试

    Maven打包如何跳过测试?正常来说,不应该这样做,因为测试可以避免很多麻烦排除一些不必要的错误,前提是测试足够规范,这里主要指junit测试,如果junit测试有问题的话,将会直接影响到mvn in ...

  8. maven 设置跳过测试

    1.在执行mvn命令时增加以下参数可以跳过测试: -DskipTests,不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下. -Dmaven.test ...

  9. Java开发学习(三十二)----Maven多环境配置切换与跳过测试的三种方式

    一.多环境开发 我们平常都是在自己的开发环境进行开发, 当开发完成后,需要把开发的功能部署到测试环境供测试人员进行测试使用, 等测试人员测试通过后,我们会将项目部署到生成环境上线使用. 这个时候就有一 ...

随机推荐

  1. C#基础之多线程与异步

    1.基本概念 多线程与异步是两个不同概念,之所以把这两个放在一起学习,是因为这两者虽然有区别,但也有一定联系. 多线程是一个技术概念,相对于单线程而言,多线程是多个单线程同时处理逻辑.例如,假如说一个 ...

  2. Windows10安装Elasticsearch IK分词插件

    安装插件 cmd切换到Elasticsearch安装目录下 C:\Users\Administrator>D: D:\>cd D:\Program Files\Elastic\Elasti ...

  3. CAD怎么算面积?这种方法你要知道

    在CAD中,打开可能都是用过CAD制图软件,这是一个比较强大的绘图软件,可以绘制出各种类型的CAD图纸文件,还可以将绘制好的图纸面积进行测量.那CAD怎么算面积?其实计算面积的方法有很多中,下面给大家 ...

  4. Android项目实战之高仿网易云音乐项目介绍

    这一节我们来讲解这个项目所用到的一些技术,以及一些实现的效果图,让大家对该项目有一个整体的认识,推荐大家收藏该文章,因为我们发布文章后会在该文章里面加入链接,这样大家找着就很方便. 目录 第1章 前期 ...

  5. Android 无源码smail进行debug

    待调试项目在AndroidManifest.xml中debugable=true 参照此处:https://blog.csdn.net/ausboyue/article/details/8018918 ...

  6. 算法之冒泡排序手写之js写法andjava写法

    对于经典算法,你是否也遇到这样的情形:学时觉得很清楚,可过阵子就忘了? 本系列文章帮助你解决这个问题. 其实排序算法,仔细品读他的名字就见名知意了. 比如冒泡排序就很形象,遍历n次,每次循环相邻元素两 ...

  7. Go语言系列:(1)在VsCode中配置Go的开发环境

    一.为什么选VSCode 这个系列的初宗是带领公司的PHPer转Go,在正式写这篇博文前,咱们先说说Go有哪些主流的IDE 1.GoLand(收费) JetBrains出品必属精品,除了贵没有其它缺点 ...

  8. AXN文档

    https://help.aliyun.com/document_detail/59705.html?spm=a2c4g.11186623.6.664.58a053afCvMM57 AXN api文档 ...

  9. JavaScript-----10.作用域

    1.作用域 一段程序代码中所用到的名字不是总是有效和可用的,而限定这个名字的可用性的代码范围就是这个名字的作用域.目的是为了提高程序的可靠性,更重要的是减少命名冲突. 在es6之前,js的作用域有:全 ...

  10. mysql5.7中timestam默认值'0000-00-00 00:00:00'报错

    在mysql5.7中设置 timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'会报错: 解决办法: mysql> set sql_mode='NO_A ...