title: Unit Test: Mocking SpringBootApplication main class with SpringApplication.run
body: <p>I have been working on this for long and could not figure out a way in mocking the main class in my Spring Boot application (with the code as provided below); without directly calling the actual class in my test class (which I need to avoid).</p>
  
  <p>I've tried with Power Mockito and MockRunner, but doesn't seem to work. How can I proceed?</p>
  
  <pre><code>import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
  
  @SpringBootApplication(exclude = KafkaAutoConfiguration.class)
  public class KafkaConsumerApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(KafkaConsumerApplication.class, args);
      }
  
  }
  
  </code></pre>
  
  <p>P.S. I'm furnishing the original test class I've written for the same, which is not appropriate way to test</p>
  
  <pre><code>import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.springframework.boot.test.context.SpringBootTest;
  import org.springframework.test.context.ActiveProfiles;
  import org.springframework.test.context.junit4.SpringRunner;
  
  @RunWith(SpringRunner.class)
  @SpringBootTest(classes = KafkaConsumerApplication.class)
  @ActiveProfiles("dev")
  public class KafkaConsumerApplicationTest {
      @Test
      public void contextLoads() {
      }
  }
  </code></pre>