gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:14:33 26 4
gpt4 key购买 nike

我试图了解 spring boot 如何管理集成测试。

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

嗯,这是第一个问题。我发现的大多数 Spring Boot 运行集成测试的示例(甚至在官方文档或 Spring 博客中),测试类都有后缀 测试 .所以,我知道他们将由 maven 运行 万无一失插件,集成测试不需要什么。

但困惑还没有结束。

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

现在我正在使用带有后缀 的 maven 故障安全插件IT 在我的 Spring Boot 集成测试中,在万无一失的情况下忽略它们:

<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>

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

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

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

最佳答案

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

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

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

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

Baeldung Tutorial on Spring Boot Testing

关于java - 无法理解 Spring Boot 如何使用 maven 管理集成测试。它是否使用故障安全插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48224313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com