title: Initialize application context during testing excluding the spring integration beans
body: <p>I am working on Spring Boot application which uses Spring Integration and Mqtt support. Here we have a test to check if the application context is started properly.</p>
  <pre><code>class ApplicationTests {
  
    private @Autowired transient ApplicationContext applicationContext;
  
    @Test
    void mainMethodTest() {
      Application.main(new String[] {});
      Assertions.assertNotNull(this.applicationContext);
    }
  }
  </code></pre>
  <p>but this test will if the Mqtt Broker is not running.</p>
  <pre><code>@Bean
    @ConfigurationProperties(prefix = &quot;mqtt&quot;)
    public MqttConnectionOptions mqttConnectOptions() {
      return new MqttConnectionOptions();
    }
  
    @Bean
    @DependsOn(&quot;mqttConnectOptions&quot;)
    public MessageHandler mqttOutbound() {
      Mqttv5PahoMessageHandler mqttv5PahoMessageHandler =
          new Mqttv5PahoMessageHandler(mqttConnectOptions(), QueueConfigs.CLIENT_ID);
      mqttv5PahoMessageHandler.setAsync(true);
      return mqttv5PahoMessageHandler;
    }
  
    @Bean
    public IntegrationFlow simulatorReadingsOutFlow() {
      return flow -&gt; flow.handle(mqttOutbound());
    }
  </code></pre>
  <p>tests will <strong>fail</strong> because the above <strong>beans</strong> will not be created during the <strong>testing</strong> without an <strong>mqtt broker</strong> running in the environment. is there a way to <strong>skip</strong> the integration flow related beans or mock them during the testing of <strong>ApplicationContext</strong>.</p>