我在解决这个问题时遇到了问题。
我在应用程序中使用缓存,并使用监听器在应用程序启动时加载它。
@EventListener(ApplicationReadyEvent.class)
public void LoadCache() {
refreshCache();
}
public void refreshCache() {
clearCache(); // clears cache if present
populateCache();
}
public void populateCache() {
// dao call to get values to be populated in cache
List<Game> games = gamesDao.findAllGames();
// some method to populate these games in cache.
}
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,这一切正常。然而,当我运行测试用例时,会出现问题,LoadCache()在运行安装程序时会调用该测试用例。我不希望在执行测试时运行它。
这是一个示例测试用例
@RunWith(SpringRunner.class)
@SpringBootTest(classes = GameServiceApplication.class)
public class GameEngineTest {
@Test
public void testSomeMethod() {
// some logic
}
}
Run Code Online (Sandbox Code Playgroud)