简体   繁体   English

在 Spring 引导应用程序中集成测试 Jms 侦听器/消费者的策略应该是什么?

[英]What should be the strategy for integration testing Jms Listeners/Consumers in a Spring Boot Application?

We have a Spring Boot JMS Listener Application that is made up of a Jms Listener, a service orchestration class, and a number of service classes underneath that orchestration class.我们有一个 Spring 引导 JMS 侦听器应用程序,它由一个 Jms 侦听器、一个服务编排 class 以及该编排 class 下的许多服务类组成。 The application requires integration testing.该应用程序需要集成测试。 Originally, I was thinking about testing it using a combination of Spring Test and Mockito, but in order to do that, I would need to use create my mocks and then use them in two separate threads (thread[main] for the test and thread[DefaultMessageListenerContainer-1] for the Jms Listener) and as far as I understand, Mockito only keeps its state in Threadlocal as shown in their documentation .最初,我正在考虑使用 Spring 测试和 Mockito 的组合来测试它,但为了做到这一点,我需要使用创建我的模拟,然后在两个单独的线程中使用它们(线程 [main] 用于测试和线程[DefaultMessageListenerContainer-1] 用于 Jms 侦听器),据我了解,Mockito将其 state 保留在 Threadlocal 中,如其文档所示。 Please see the quote below.请参阅下面的报价。

Mockito uses ThreadLocal state to implement a gorgeous mocking syntax in a language full of constraints (yes, it's java). Mockito 使用 ThreadLocal state 在充满约束的语言中实现了华丽的 mocking 语法(是的,它是 java)。 Fortunately, every time you interact with Mockito framework it validates the ThreadLocal state in case you misused the api.幸运的是,每次您与 Mockito 框架交互时,它都会验证 ThreadLocal state,以防您误用 api。

Given this, I was thinking about having two separate test classes, one which will test that the listener is properly wired and it is able to take a message, and the other will test the service orchestrator and the service classes behaviour.鉴于此,我正在考虑有两个单独的测试类,一个将测试侦听器是否正确连接并且能够接收消息,另一个将测试服务编排器和服务类的行为。 Please let me know if there are other alternatives to this strategy that allows me to test both under the same test class.请让我知道是否有其他替代方法可以让我在同一个测试 class 下测试两者。

Thanks,谢谢,

Juan胡安

In light of what I discovered here , I will be going with creating an integration test to test the JMS Listener and service orchestrator and minimize the number of separate integration tests to keep the build times low and still maintain the quality for coverage.根据我在这里的发现,我将创建一个集成测试来测试 JMS 侦听器和服务编排器,并最大限度地减少单独集成测试的数量,以保持低构建时间并保持覆盖质量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM