gpt4 book ai didi

spring - @CamelSpringTest 和@CamelSpringBootTest 有什么区别?

转载 作者:行者123 更新时间:2023-12-05 02:41:01 29 4
gpt4 key购买 nike

我刚刚开始一个结合了 Spring Boot 和 Apache Camel 的项目(这看起来是一个非常好的组合)。

关于使用 JUnit 5 进行测试,Google 提出了 this page .如果您想同时拥有 Spring 和 Camel 的注释(我想要的),它建议使用 @CamelSpringTest

在页面的 和 处有关于 JUnit 4 测试迁移的建议,建议:

Usage of @RunWith(CamelSpringRunner.class) should be replaced with@CamelSpringTest...Usage of @RunWith(CamelSpringBootRunner.class) should be replaced with@CamelSpringBootTest

我的问题是针对新项目/测试:两者在使用方面有何不同。
代码当然有差异,但我不知道原因是什么:

Camel Spring 测试:

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@ExtendWith(SpringExtension.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@TestExecutionListeners(
value = {
CamelSpringTestContextLoaderTestExecutionListener.class,
StopWatchTestExecutionListener.class
},
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
public @interface CamelSpringTest {

}

Camel SpringBoot测试

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@ExtendWith(SpringExtension.class)
@TestExecutionListeners(
value = {
CamelSpringTestContextLoaderTestExecutionListener.class,
CamelSpringBootExecutionListener.class,
StopWatchTestExecutionListener.class
},
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
public @interface CamelSpringBootTest {

}

最佳答案

区别很简单:测试是否在SpringBoot项目中运行?

Camel 可用于纯 Spring 项目(无需 Boot)。在这样的项目中,您可以扩展 CamelSpringTestSupport 来编写测试,也可以使用 @CamelSpringTest 注释。然后针对该环境启动并初始化测试。

当您使用 Camel in a SpringBoot project 时,Camel 可以通过自动配置等方式利用此环境。因此,您必须使用另一个注释 @CamelSpringBootTest 来编写测试。参见 here for an example .

因此,这两个注释只是针对不同项目类型的两个不同 Camel 测试设施的“激活器”。这些只是 Spring 的设施。查看此页面以获取 even more Camel test facilities .

这也是围绕 Camel 测试造成许多困惑的根源。有太多的测试变体,Spring、SpringBoot、JUnit 4、JUnit 5 等。真的很难知道什么测试设置组合需要什么注释。

关于spring - @CamelSpringTest 和@CamelSpringBootTest 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68313960/

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