我有一个类注入StreamBridge发送有时一些事件。使用该类的测试失败,因为不存在bean。我试过
@MockBean StreamBridge StreamBridge
使用Mockito进行测试,但由于一些静态内容,它失败了。试图使用
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
<version>${spring.cloud.stream.version}</version>
<type>test-jar</type>
<scope>test</scope>
<classifier>test-binder</classifier>
</dependency>
,但没有帮助。我也试过了
@ImportAutoConfiguration(TestChannelBinderConfiguration.class)
但是TestChannelBinderConfiguration也不存在
任何想法我怎么能使这个StreamBridge可用于测试?
看一下这些测试,看看StreamBridge
是如何在框架中测试的:
https://github.com/spring-cloud/spring-cloud-stream/blob/main/core/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/function/StreamBridgeTests.java