What problem does it solve?
Unit testing asynchronous and scheduled methods is hard because real executors, timing, and thread scheduling make tests slow, flaky, or nondeterministic. This Skill shows patterns to isolate async logic, mock dependencies, and verify scheduling behavior without relying on actual cron triggers or background executors.
Core Features & Use Cases
- Direct invocation of @Async/@Scheduled methods to validate business logic without starting schedulers or thread pools.
- CompletableFuture and Awaitility guidance to assert async results with timeouts and avoid hanging tests.
- Mocking and verification patterns for dependencies called by background tasks, and examples for testing exception handling and execution counts.
- Use Case: Test a cache refresh @Scheduled method by calling it directly and verifying repository interactions, or validate an @Async notification method by awaiting the CompletableFuture result and asserting mock invocations.
Quick Start
Call the @Async or @Scheduled method directly in your unit test, await any returned CompletableFuture with a timeout, and verify mocked dependencies were invoked as expected.