When using Kotlin, the SpringBootTest.UseMainMethod.ALWAYS option is unable to locate the main method. The main/blocker issue here is not being able to use the ApplicationContextInitializers that are added in the main method.

  • Spring Boot Version: 3.0.0-RC2
  • Reproducer Repo: https://github.com/PedroAlvarado/Use-Main-Method-Bug
  • Documentation: https://docs.spring.io/spring-boot/docs/3.0.0-RC2/reference/htmlsingle/#features.testing.spring-boot-applications.using-main
  • Error Log Example:
Caused by: java.lang.IllegalStateException: Main method not found on 'com.example.demo.DemoApplication'
    at org.springframework.util.Assert.state(Assert.java:97)
    at org.springframework.boot.test.context.SpringBootContextLoader.getMainMethod(SpringBootContextLoader.java:156)
    at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:125)
    at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:105)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:183)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
    ... 87 more