无法理解 Spring Boot 如何使用 maven 管理集成测试。它是不是使用故障安全插件?

     2023-02-26     66

关键词:

【中文标题】无法理解 Spring Boot 如何使用 maven 管理集成测试。它是不是使用故障安全插件?【英文标题】:Can't understand how Spring Boot manage integration tests with maven. Is it uses failsafe plugin or not?无法理解 Spring Boot 如何使用 maven 管理集成测试。它是否使用故障安全插件? 【发布时间】:2018-06-21 19:13:24 【问题描述】:

我试图理解 Spring Boot 如何管理集成测试。

基本上,在任何具有集成测试的项目中,对此负责的插件是 maven failsafe 插件。默认情况下,它会执行所有带有 IT 后缀的类。例如:MyServiceIT.java

嗯,这是第一个问题。我发现的大多数 Spring Boot 运行集成测试的示例(甚至在官方文档或 Spring 博客中)测试类都有后缀 Test。所以,我知道它们将由 maven surefire 插件运行,这对于集成测试来说是不可取的。

但混乱还没有结束。

spring boot maven 插件文档says nothing about the failsafe plugin 如果目标是运行集成测试。但是,如果您想跳过它们,请在文档中查看the failsafe plugin appears。

目前,我在我的 Spring Boot 集成测试中使用带有后缀 IT 的 maven 故障安全插件,但肯定会忽略它们:

<plugin>
    <!-- for unit tests -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/*IT.java</exclude>
        </excludes>
    </configuration>
</plugin>

<plugin>
    <!--for integrations tests-->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <skipITs>$skipITs</skipITs>
    </configuration>
</plugin>

但另一位同事在他的 Spring Boot 集成测试(在另一个项目中)中使用了后缀 Test,并声称这是正确的后缀¹。

所以...我做错了什么? Spring Boot 的这种“奇怪”设置如何用于集成测试?

¹。 Sonar 能够获得他的测试覆盖率,而我的测试没有。我们正在使用 Cobertura maven 插件。我认为原因是他的测试是在surefire插件上运行的,但是在故障安全插件上我需要在pom.xml上进行额外配置,也许还需要在Sonar上。

【问题讨论】:

这个 Spring 网站也使用您的方法解决了这个问题:[使用 Maven Cargo 插件进行集成测试] (baeldung.com/integration-testing-with-the-maven-cargo-plugin) 所以基本上,您没有错。 【参考方案1】:

我认为您不需要使用故障安全插件。 Spring Boot 文档告诉您使用的 spring-boot-starter-parent 参考包含任何人甚至可以考虑使用的所有内容,包括其中的厨房水槽。

故障安全插件是进行集成测试的一种方法。这会留下一些手动配置。

但如果您使用的是 spring boot,您应该使用 spring boot 附带的内置工具。毕竟这就是使用弹簧靴的全部意义所在。他们为你做了很多。我怀疑您在 Spring Boot 文档中没有看到太多关于 Spring 文档中提到的故障安全插件的原因是他们不希望人们使用它。

请参阅以下教程。这很简单,但它是一个很好的起点:

Baeldung Tutorial on Spring Boot Testing

【讨论】:

Spring Boot Async 方法如何使用 ThreadPool 处理请求

...ngThreadPool【发布时间】:2020-09-1001:32:55【问题描述】:我无法理解异步是如何工作的。我知道网络服务器有自己的线程池来处理多个请求。当我们使用SpringBoot实现异步Web服务并使用TaskExecutor配置"n"个线程时,这是否意味着 查看详情

如何解决在使用 Spring Boot 和 Spring Security 启用 CSRF 后无法正常工作的登录问题?

】如何解决在使用SpringBoot和SpringSecurity启用CSRF后无法正常工作的登录问题?【英文标题】:HowcanIfixtheloginissuewhichisnotworkingafterCSRFisenabedwithSpringBootandSpringSecurity?【发布时间】:2019-10-3005:01:09【问题描述】:我有一个SpringBoot应用... 查看详情

如何理解 Spring Boot 应用程序已准备好工作?

】如何理解SpringBoot应用程序已准备好工作?【英文标题】:Howtounderstandthatspringbootapplicationisreadytowork?【发布时间】:2018-10-2416:41:10【问题描述】:我在春季有几个微服务。其中之一是配置服务器。我尝试使用docker-compose完全启动... 查看详情

如何使用 Spring Boot 配置文件

...en命令mvnspring-boot:run-Dspring.profiles.active=dev它不起作用,我无法使用mvnspring- 查看详情

从spring-boot开始深入理解spring系列——spring-boot使用servletsfilterlistenerinterceptor(代码片段)

文章目录基础概念理解对比深入理解:原理详解生命周期、执行顺序的理解实战:示例应用项目实战应用场景附源码下载参考博客基础概念理解servletServlet是一种运行服务器端的java应用程序,具有独立于平台和协议的... 查看详情

如何使用 Spring Boot 配置 Shiro

...序在SpringBoot中启动,我的Shiro环境得到设置。但是我只是无法弄 查看详情

如何搭建springboot

Helloworld使用传统的springmvc,需要配置web.xml,applicationContext.xml,然后打包为war在tomcat中运行,而如果使用springboot,一切都变得简单起来了。下面使用Maven来创建springboot的webapp工程pom.xml4.0.0org.springframeworkgs-spring-boot0.1.0org.springframework.b... 查看详情

用 HikariCP 深入理解 Spring boot

】用HikariCP深入理解Springboot【英文标题】:DeepunderstandingofSpringbootwithHikariCP【发布时间】:2021-08-2114:43:00【问题描述】:我有一个springboot应用程序,它使用spring数据和hikaricp进行数据库连接池。我注意到以下对我来说很奇怪的行... 查看详情

如何通过 Maven 使用 Netbeans 调试 Spring Boot

...发现写下来作为其他人的问答。问题是Netbeans的默认配置无法在调试模式下正确启动Spring,当您搜索Intern 查看详情

Spring Boot 应用程序使用 spring-boot-starter-actuator 给出“无法启动 tomcat”异常

】SpringBoot应用程序使用spring-boot-starter-actuator给出“无法启动tomcat”异常【英文标题】:Springbootapplicationgives"unabletostarttomcat"exceptionwithspring-boot-starter-actuator【发布时间】:2020-07-2717:16:20【问题描述】:我有我的spring-boot应... 查看详情

如何使用 Spring Boot 嵌入式 tomcat 设置会话超时

...beddedtomcat【发布时间】:2016-12-0300:51:31【问题描述】:我无法在我的JhipsterWebApp中设置会话超时(springboot+Springsecurity+angularJS)我只是做了最简单的方法:.../***Configurationofweb 查看详情

无法使用 Spring Boot 应用程序连接到 Docker 映像

】无法使用SpringBoot应用程序连接到Docker映像【英文标题】:Notabletoconnecttodockerimagewithaspringbootapplication【发布时间】:2019-08-2822:49:11【问题描述】:DockerfileFROMopenjdk:8ADDtarget/docker-spring-boot.jardocker-spring-boot.jarEXPOSE8085ENTRYPOIN 查看详情

如何在 Spring Boot 中手动新建实例中使用 @Autowired

...其中的@Autowired成员不会生效。但我认为在某些情况下,无法避免新的实例。比如一个Runnabl 查看详情

如何使用 YAML 文件在 Spring Boot 中配置 Swagger?

...在扫描包并创建漂亮的文档,但我想使用我的YAML(如果无法使用YAML,则使用JSON)文件。这是我的Swagger配置类:@Configuration 查看详情

如何使用 Spring Boot 和 Thymeleaf 设置 CSS

...用。我在***上检查了很多答案,尝试了所有方法,但仍然无法正常工作。这是我所做的一个示例:我的te 查看详情

Spring Security,Boot:安全规则无法正常工作

】SpringSecurity,Boot:安全规则无法正常工作【英文标题】:SpringSecurity,Boot:SecurityRulesnotworkingasexcepted【发布时间】:2017-10-1904:39:22【问题描述】:我对SpringBoot很陌生,我正在尝试在我的应用程序中使用SpringBoot来实现SpringSecurity和... 查看详情

无法使用 Spring Boot 更新现有实体

】无法使用SpringBoot更新现有实体【英文标题】:ExistingentitycannotbeupdatedwithSpringBoot【发布时间】:2016-06-0809:07:49【问题描述】:我的SpringBoot应用有以下类:董事会(JPA实体)@Entity@Table(name="board")publicclassBoardpublicstaticfinalintIN_PROGRE... 查看详情

无法使用 Spring-Boot 创建多个数据源

】无法使用Spring-Boot创建多个数据源【英文标题】:UnabletocreatemultipledatasourceswithSpring-Boot【发布时间】:2017-04-1712:22:51【问题描述】:tomcat出现以下错误:09:06:18,168WARNING[org.apache.tomcat.jdbc.pool.PooledConnection](ServerServiceThreadPool--6)Notl 查看详情