Spring cloud SpringCloudStream集成测试,如何确保应用程序资源不被使用

Spring cloud SpringCloudStream集成测试,如何确保应用程序资源不被使用,spring-cloud,spring-cloud-stream,spring-boot-test,spring-cloud-stream-binder-kafka,Spring Cloud,Spring Cloud Stream,Spring Boot Test,Spring Cloud Stream Binder Kafka,我正在尝试为我的云流应用程序做一些集成测试。到目前为止,我观察到的一个主要问题是TestChannelBinderConfiguration一直在选择src/main/java/resources/application.yml中指定的配置,而不是将其保留为空(因为/src/test/resources/中没有配置文件) 如果删除application.yml文件或删除所有与SpringCloud流相关的配置,则测试通过。如何确保TestChannelBinderConfiguration不会拾

我正在尝试为我的云流应用程序做一些集成测试。到目前为止,我观察到的一个主要问题是TestChannelBinderConfiguration一直在选择
src/main/java/resources/application.yml
中指定的配置,而不是将其保留为空(因为
/src/test/resources/
中没有配置文件)

如果删除
application.yml
文件或删除所有与SpringCloud流相关的配置,则测试通过。如何确保TestChannelBinderConfiguration不会拾取
application.yml
文件

  @Test
  public void echoTransformTest() {
    try (ConfigurableApplicationContext context =
        new SpringApplicationBuilder(
              TestChannelBinderConfiguration.getCompleteConfiguration(DataflowApplication.class))
            .properties(new Properties())
            .run("--spring.cloud.function.definition=echo")) {
      InputDestination source = context.getBean(InputDestination.class);
      OutputDestination target = context.getBean(OutputDestination.class);

      GenericMessage<byte[]> inputMessage = new GenericMessage<>("hello".getBytes());

      source.send(inputMessage);
      assertThat(target.receive().getPayload()).isEqualTo("hello".getBytes());
    }
  }
@测试
公共测试(){
try(可配置的应用程序上下文)=
新的SpringApplicationBuilder(
TestChannelBinderConfiguration.getCompleteConfiguration(DataflowApplication.class))
.properties(新属性())
.run(“--spring.cloud.function.definition=echo”)){
InputDestination源=context.getBean(InputDestination.class);
OutputDestination target=context.getBean(OutputDestination.class);
GenericMessage inputMessage=新的GenericMessage(“hello”.getBytes());
source.send(输入消息);
assertThat(target.receive().getPayload()).isEqualTo(“hello.getBytes());
}
}

我通过执行以下操作解决了此问题:

SpringBootTest(properties = {"spring.cloud.stream.function.definition=reverse"})
@Import(TestChannelBinderConfiguration.class)
public class EchoTransformerTest {

  @Autowired private InputDestination input;

  @Autowired private OutputDestination output;

  @Test
  public void testTransformer() {
    this.input.send(new GenericMessage<byte[]>("hello".getBytes()));
    assertThat(output.receive().getPayload()).isEqualTo("olleh".getBytes());
  }
}
SpringBootTest(属性={“spring.cloud.stream.function.definition=reverse”})
@导入(TestChannelBinderConfiguration.class)
公共类EchoTransformerTest{
@自动连线专用输入目的地输入;
@自动连线专用输出目的地输出;
@试验
公共void testTransformer(){
this.input.send(新的GenericMessage(“hello.getBytes()));
断言(output.receive().getPayload()).isEqualTo(“olleh.getBytes());
}
}
并将application.yml添加到
test/resources
中,这确保我们不会读取src/resources应用程序属性

另一种方法是明确定义
@TestPropertySource(locations=“test.yml”)

不要将
@springbootest
添加到测试类中?@GaryRussell-我已经尝试了两种方法。。。有无springboottestOh;您正在使用
SpringApplicationBuilder
;对不起,错过了。看见