欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

springboot打包如何忽略Test单元测试

时间:2022-03-28 08:40:33|栏目:JAVA代码|点击:

springboot打包忽略Test单元测试

在maven pom.xml中加入配置:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.20.1</version>
    <configuration>
        <skipTests>true</skipTests>
    </configuration>
</plugin>

spring boot跳过maven test

在eclipse每次使用run as -> maven install, 总是运行junit test,一些test还关联数据库, 有的比较危险。怎么跳过测试skip test呢?

spring-boot- maven -plugin 插件 已经集成了maven-surefire-plugin插件

只需要在pom.xml里增加

<properties>
    <!-- maven方式跳过maven test, 等同$ mvn package -Dmaven.test.skip=true -->
    <!-- <maven.test.skip>true</maven.test.skip> -->
    <!-- surefire plugin方式跳过maven test, 等同$ mvn package -DskipTests -->
    <skipTests>true</skipTests>
</properties>

这里需要注意的是maven.test.skip,跳过了一切与test相关的类, 连.class都不生成, 如果允许junit测试会发现ClassNotFound错误,

而skipTests会编译测试类,即生成.class文件,只是不运行测试类, 你可以手动运行测试类。

以前没有用spring boot的时候是这样跳过maven test的, 在pom.xml添加:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12.4</version>
    <configuration>
        <skipTests>true</skipTests>
    </configuration>
</plugin>

参考:http://maven.apache.org/plugins-archives/maven-surefire-plugin-2.12.4/examples/skipping-test.html

上一篇:Java关于远程调试程序教程(以Eclipse为例)

栏    目:JAVA代码

下一篇:java实现文件重命名功能

本文标题:springboot打包如何忽略Test单元测试

本文地址:http://www.codeinn.net/misctech/197477.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有