
Unit Test Scheduled Async
Unit-test patterns for Spring @Scheduled and @Async methods using JUnit 5, Mockito, and Awaitility.
- skills.sh installs
- 3.9K
- GitHub stars
- 372
- last updated
- Aug 21, 2026
What it does
- Covers calling
@Asyncand@Scheduledmethods directly, mocking dependencies, and verifying CompletableFuture results and execution counts - Includes examples for cron expression checks, retry validation, exception wrapping in
ExecutionException, and Awaitility race-condition waits - Enforces timeouts on
CompletableFuture.get()and AwaitilityatMost()so tests fail instead of hanging - Designed for Spring Java projects testing background tasks, periodic jobs, or thread pool behavior without waiting for real schedules
Install
$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-scheduled-async -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
Unit Testing @Scheduled and @Async Methods
Overview
Patterns for unit testing Spring @Scheduled and @Async methods with JUnit 5. Test CompletableFuture results, use Awaitility for race conditions, mock scheduled task execution, and validate error handling — without waiting for real scheduling intervals.
When to Use
- Testing
@Scheduledmethod logic - Testing
@Asyncmethod behavior - Verifying
CompletableFutureresults - Testing async error handling
- Testing cron expression logic without waiting for actual scheduling
- Validating thread pool behavior and execution counts
- Testing background task logic in isolation
Instructions
- Call
@Asyncmethods directly — bypass Spring's async proxy; the annotation is irrelevant in unit tests - Mock dependencies with
@Mockand@InjectMocks(Mockito) - Wait for completion — use
CompletableFuture.get(timeout, unit)orawait().atMost(...).untilAsserted(...) - Call
@Scheduledmethods directly — do not wait for cron/fixedRate; the annotation is ignored in unit tests - Test exception paths — verify
ExecutionExceptionwrapping onCompletableFuture.get()
Details
- Repository
- github.com/giuseppe-trisciuoglio/developer-kit
- Categories
- Testing & QA, Java & JVM
- First seen
- May 16, 2026
More from giuseppe-trisciuoglio/developer-kit
All 95- Rag3.9K
- Unit Test Utility Methods3.9K
- Qdrant3.9K
- Unit Test Exception Handler3.9K
- Unit Test Mapper Converter3.9K
- Langchain4j Ai Services Patterns3.9K
- Unit Test Caching3.9K
- Unit Test Config Properties3.9K
- Unit Test Application Events3.9K
- Langchain4j Vector Stores Configuration3.9K
- Langchain4j Mcp Server Patterns3.9K
- Aws Sdk Java V2 S33.9K
- Langchain4j Testing Strategies3.9K
- Aws Sdk Java V2 Dynamodb3.9K
- Aws Rds Spring Boot Integration3.9K
- Nextjs Deployment3.9K
- Aws Sdk Java V2 Lambda3.9K
- Aws Sdk Java V2 Core3.9K
- Aws Sdk Java V2 Bedrock3.9K
- Aws Sdk Java V2 Messaging3.9K
- Aws Sdk Java V2 Secrets Manager3.9K
- Aws Sdk Java V2 Kms3.9K
- Aws Sdk Java V2 Rds3.9K
- Nestjs Drizzle Crud Generator3.8K
Similar to Unit Test Scheduled Async
More Testing & QA
unit-test-application-eventsgiuseppe-trisciuoglio/developer-kit3.9K installsUnit test patterns for Spring events that mock publishers and call listeners directly without a booted context.
unit-test-service-layergiuseppe-trisciuoglio/developer-kit4K installsMockito-based unit test patterns for @Service classes that isolate business logic from databases and external APIs.
java-testingpluginagentmarketplace/custom-plugin-java917 installsJava testing guide covering JUnit 5, Mockito, AssertJ, and Spring Boot integration tests with Testcontainers.
concurrency-reviewdecebals/claude-code-java402 installsJava concurrency review skill covering virtual threads, Spring @Async pitfalls, and CompletableFuture error-handling patterns.
131-java-testing-unit-testingjabrena/plinth134 installsJava unit testing guidance for JUnit 5, AssertJ, and Mockito, with compile-first and full-verify gates.