欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-03-09 19:55:14
springboot打包忽略test单元测试在maven pom.xml中加入配置: org.apache.maven.plugins&...

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

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。