I recently added an ApplicationStartup class to my SpringBoot project
@Component
public class ApplicationStartup
implements ApplicationListener<ApplicationReadyEvent> { ...
It implements ApplicationListener.
Now when I run my old JUNit tests that have nothing to do with that class, The testrunner tries to Run my StartupListener, which is neither necessary not appropriate in these cases.
How do I skip the ApplicationListener when my tests initialize?
@RunWith(SpringRunner.class)
@SpringBootTest
public class SubmissionItemManagerTest {...
You can mock your
ApplicationStartupclassAdd this declaration to your test case:
This will create a mocked instance of
ApplicationStartupand mark it as@Primaryin your test context thereby replacing the actual instance ofApplicationStartup.