spring-boot - 批量运行 Spring-Boot + Camel 测试失败

标签 spring-boot kotlin apache-camel camel-test

对于使用 Spring-Boot 2.7.0 和 Apache Camel 3.17.0 的 Kotlin 应用程序,我遇到了一个相当令人惊讶的问题:我有一组单独运行良好的 JUnit 5 测试用例(使用 mvn test -DTest="MyTest");但是当通过 mvn test 或在 IntelliJ IDEA 中批量运行时,某些测试用例会因 org.apache.camel.FailedToCreateRouteException... 失败,因为无法在已启动的 CamelContext 上设置跟踪器.

有趣的是,这些测试用例没有启用跟踪。对于大多数测试,我的测试设置如下所示:

@CamelSpringBootTest
@SpringBootTest(
    classes = [TestApplication::class],
    properties = ["camel.springboot.java-routes-include-pattern=**/SProcessingTestRoute"]
)
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
@UseAdviceWith
internal class ProcessingTest(
    val template: FluentProducerTemplate,
    @Value("classpath:test-resource") private val TestResource: Resource,
    val camelContext: CamelContext
) {
    @EndpointInject("mock:result")
    lateinit var resultMock: MockEndpoint

    @Test
    fun `test my route`() {
        AdviceWith.adviceWith(camelContext, "processing-route") { route ->
            route.weaveAddLast().to("mock:result")
        }
        resultMock.expectedCount = 1
        camelContext.start()

        // ...
        // here comes the actual test
    }
}

有一些测试我不建议路线;即,这些测试用例没有 @AdviceWith 注解,并且这些测试用例在批量运行期间不会失败。

调试这个问题很困难;因此,我非常感谢任何有关潜在原因的指示、提示或假设,以及如何缩小问题范围的想法!

最佳答案

您可能需要为每个测试提供一个新的 Camel 上下文。尝试将 @DirtiesContext 添加到每个测试类。如果这不起作用,请将其添加到每个测试方法中。

关于spring-boot - 批量运行 Spring-Boot + Camel 测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73189547/

相关文章:

java - 带有 ImageUpload 端点的空文件

java - String.class 在 Camel-Context 中拆分使用

apache-camel - 如何在多个 Apache Camel 路由中包含常见行为?

java - spring 应用程序启动前的 spring boot setup logging

spring-boot - 我的@WebMvcTest 测试类如何在 Spring Boot 中使用此 JDBC 身份验证配置进行初始化?

spring-boot - 用于启用 SSL 的 Spring Boot Cassandra 配置

swift - KMM iOS 崩溃,因为 `Flow` 没有正确抛出,异常与 @Throws 指定的类不匹配

kotlin - 如何为 Kotlin 实现 applyif?

android - 在 Android 的导航架构组件中将复杂对象作为参数传递

maven - 使用 cxf jar 打包 Camel 项目