springboot打包忽略单元测试 springboot打包怎样忽略Test单元测试

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

springboot打包忽略单元测试 springboot打包怎样忽略Test单元测试

yangxinhu_coder   2021-11-04 我要评论
想了解springboot打包怎样忽略Test单元测试的相关内容吗,yangxinhu_coder在本文为您仔细讲解springboot打包忽略单元测试的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:springboot单元测试,打包忽略Test,单元测试,忽略Test单元测试,下面大家一起来学习吧。

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

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们