Skip to content

Introduce NoOpTaskScheduler for disabling @Scheduled tasks in test setups #28073

Closed
@membersound

Description

@membersound

If an application defines a @Scheduled(fixedRateString = "PT6H") tasks, then this task will be running on any @SpringBootTest junit test that does not explicit mock the bean containing the scheduled task.

@Service
public class SchedulerService {
    @Scheduled(fixedRateString = "PT6H")
    public void runOnStartup() {

   }
}

This gets tedious if there are many more @Scheduled tasks in the application that launch on startup by usage of fixedRate or fixedRateString.

It would be great if there could be a possibility to completely deactivate the execution of @Scheduled tasks in junit.

Just like it is possible to deactivate any @Cacheable annotation by simply setting spring.cache.type=none dring junit tests.

Something like: spring.enable.scheduling=false (default: true)

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions