title: Test Spring boot Application startup using Junit
body: <p>I have some business logic that runs when Spring boot application starts (i.e in main method)</p>
  <pre><code>@SpringBootApplication
  @EnableGatewayService
  @EnableAsync
  @Slf4j
  public class AuthOpsApplication {
       public static void main(String[] args) throws IOException {
          application.addListeners(new WEPFallbackListener());
          application.addListeners(new SaeListener());
          application.run(args);
          // some business logic
          log.info(&quot;logs some info of the business logic&quot;);
  
      }
  }
  </code></pre>
  <p>I want to write a test case to check if the log.info is getting printed and its value is as expected. I do not want to test the business logic as a standalone code, I would like to run  the main function and somehow read the log that it puts out, Is this possible?</p>
  <p>What I tried:</p>
  <pre><code>import org.springframework.test.context.junit4.SpringRunner;
  import uk.org.lidalia.slf4jtest.TestLogger;
  import uk.org.lidalia.slf4jtest.TestLoggerFactory;
  import org.springframework.boot.test.autoconfigure.actuate.metrics.AutoConfigureMetrics;
  import org.springframework.test.context.ActiveProfiles;
  
  @RunWith(SpringRunner.class)
  @SpringBootTest(classes = AuthOpsApplication.class)
  @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
  @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY)
  @ActiveProfiles(&quot;test&quot;)
  @AutoConfigureMetrics
  public class LogTest {
      TestLogger logger = TestLoggerFactory.getTestLogger(AuthOpsApplication.class);
  
  
      @Test
      public void testAnyLog() throws IOException {
          System.out.println(logger.getLoggingEvents());
  
      }
  
      @After
      public void clearLoggers() {
          TestLoggerFactory.clear();
      }
  }
  </code></pre>
  <p>This runs successfully and creates all the Beans but does not actually call the main() method of my AuthOpsApplication class.</p>
  <p>( I can say this because the System.out.println() that I did gives all the other logs except the ones in main() method).</p>
  <p>Thanks in advance for the help.</p>