Spring Test Dynamic @Scheduled
사용법
@RunWith(SpringRunner.class)
@SpringBootTest
public class NpushManagerDAOTest {
@Test
public void myTest() {
// run test logic
}
@TestConfiguration
static class SchedulingTestConfig implements SchedulingConfigurer {
@Autowired
private MyService service;
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
List<IntervalTask> taskList = taskRegistrar.getFixedDelayTaskList();
List<IntervalTask> newTaskList = new ArrayList<>();
for (IntervalTask task : taskList) {
ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
if (runnable.getTarget() instanceof MyService) {
newTaskList.add(new IntervalTask(runnable, CUSTOM_DELAY, CUSTOM_DELAY));
}
}
taskRegistrar.setFixedDelayTasksList(newTaskList);
}
}
}Last updated