Unit testing 如何在Camel测试中启用@UseAdviceWith

Unit testing 如何在Camel测试中启用@UseAdviceWith,unit-testing,apache-camel,Unit Testing,Apache Camel,我不熟悉Camel,我正在尝试编写一些使用Spring上下文和@useadvicewithannotation的测试。我需要的是使@UseAdviceWith annotation正常工作,以便在修改之前不启动Camel上下文,我找到了两种方法:一种是添加像《Camel in Action》一书中提到的加载程序属性 @ContextConfiguration(locations = {"classpath:/META-INF/spring/testContext.xml"}, l

我不熟悉Camel,我正在尝试编写一些使用Spring上下文和@useadvicewithannotation的测试。我需要的是使@UseAdviceWith annotation正常工作,以便在修改之前不启动Camel上下文,我找到了两种方法:一种是添加像《Camel in Action》一书中提到的加载程序属性

@ContextConfiguration(locations = {"classpath:/META-INF/spring/testContext.xml"},
        loader = CamelSpringDelegatingTestContextLoader.class)
另一种方法是使用

@BootstrapWith(CamelTestContextBootstrapper.class)
区别是什么?在单元测试中使用它的正确方法是什么?我目前必须使用的Camel版本是2.15.3

有什么区别

@BootstrapWith是在Spring 4.1中引入的 对于较旧的Spring版本,请使用@ContextConfigurations加载程序参数 它们都是Spring注释,而不是Camel

在单元测试中使用它的正确方法是什么

骆驼报盘。要使用@UseAdviceWith,您必须使用

如果您使用的是SpringBoot,则@UseAdviceWith存在一个问题

Camel3.0支持JUnit5。骆驼2.x支持JUnit4或JUnit5的经典跑步者

一般来说,如何正确配置Camel-Spring测试是一个巨大的难题,因为它取决于测试模式,至少取决于Camel、JUnit和Spring的版本。如果您添加SpringBoot,则会有另一个依赖项

然而,这是一个工作路线测试类签名,包含Camel 2.24、SpringBoot 2.1、Spring 5.1和JUnit Vintage

@RunWith(CamelSpringBootRunner.class)
@SpringBootTest(
    classes = {
        [Classes to load for the test]
    }
)
@EnableAutoConfiguration
@UseAdviceWith
public class MyTestClass { ... }
有什么区别

@BootstrapWith是在Spring 4.1中引入的 对于较旧的Spring版本,请使用@ContextConfigurations加载程序参数 它们都是Spring注释,而不是Camel

在单元测试中使用它的正确方法是什么

骆驼报盘。要使用@UseAdviceWith,您必须使用

如果您使用的是SpringBoot,则@UseAdviceWith存在一个问题

Camel3.0支持JUnit5。骆驼2.x支持JUnit4或JUnit5的经典跑步者

一般来说,如何正确配置Camel-Spring测试是一个巨大的难题,因为它取决于测试模式,至少取决于Camel、JUnit和Spring的版本。如果您添加SpringBoot,则会有另一个依赖项

然而,这是一个工作路线测试类签名,包含Camel 2.24、SpringBoot 2.1、Spring 5.1和JUnit Vintage

@RunWith(CamelSpringBootRunner.class)
@SpringBootTest(
    classes = {
        [Classes to load for the test]
    }
)
@EnableAutoConfiguration
@UseAdviceWith
public class MyTestClass { ... }

非常感谢。我没有使用SpringBoot,只使用带有XML配置的@RunWithCamelSpringJUnit4ClassRunner.class。我说得对吗,在@SpringBootTest和RunWithCamelSpringBootRunner.class的情况下,我不需要添加BootstrapWith以使UseAdviceWith功能正常工作?是的,我这么认为是因为CamelSpringBootRunner对于SpringBoot Camel测试的作用可能与@BootstrapWith对于没有BootBoot的SpringCamel测试的作用相同谢谢。我没有使用SpringBoot,只使用带有XML配置的@RunWithCamelSpringJUnit4ClassRunner.class。我说得对吗,在@SpringBootTest和RunWithCamelSpringBootRunner.class的情况下,我不需要添加BootstrapWith以使UseAdviceWith功能正常工作?是的,我这么认为是因为CamelSpringBootRunner可能对SpringBoot骆驼测试起作用,就像@BootstrapWith对没有靴子的SpringCamel测试起作用一样