首页 > 解决方案 > Spring Cloud Stream Test 在消息的有效负载中硬编码“Hello World”

问题描述

我正在尝试 Spring Cloud Stream,当我尝试运行最简单的测试之一时(原始测试可在此处获得:https ://github.com/spring-cloud/spring-cloud-stream/blob/master/spring- cloud-stream-test-support/src/test/java/org/springframework/cloud/stream/test/disable/AutoconfigurationDisabledTest.java )

使用:Java 1.8 SpringBoot 2.1.5.RELEASE spring-cloud.version:Greenwich.RELEASE

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@DirtiesContext
public class ExampleTest {

    @Autowired
    public MessageCollector messageCollector;

    @Autowired
    public Processor processor;

    @SuppressWarnings("unchecked")
    @Test
    public void testAutoconfigurationDisabled() {
        this.processor.input().send(MessageBuilder.withPayload("empty").build());

        Message<String> response = (Message<String>) this.messageCollector.forChannel(this.processor.output()).poll();

        Assertions.assertThat(response).isNotNull();
        Assertions.assertThat(response.getPayload()).isEqualTo("Hello World");
    }
}

测试通过了,但不应该。消息以“空”发送,这就是我希望收到的,但接收到的有效负载始终是“Hello World”

标签: javaspringspring-bootspring-cloud-stream

解决方案


从“Hello world”更改为“”后,请确保您已经编译了您的测试类。当我将 maven 与 Intellij 一起使用并从 maven 视图运行测试时,我遇到了未编译的测试类的情况,并且总是得到以前的结果。


推荐阅读