对于使用 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/