unit-test-caching
This skill equips you with reusable test patterns for Spring caching annotations without requiring full application context. It covers cache hit/miss behavior, invalidation logic, SpEL key generation, and conditional caching scenarios using in-memory CacheManager.
unit-test-caching generates test patterns for Spring Cache annotations including @Cacheable, @CacheEvict, and @CachePut verification.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-06-22
unit-test-caching generates test patterns for Spring Cache annotations including @Cacheable, @CacheEvict, and @CachePut verification. This skill equips you with reusable test patterns for Spring caching annotations without requiring full application context. It covers cache hit/miss behavior, invalidation logic, SpEL key generation, and conditional caching scenarios using in-memory CacheManager.
Use it when
- unit-test-caching provides patterns to verify cache hit/miss by counting repository invocations with Mockito.verify().
- unit-test-caching covers @CacheEvict testing by demonstrating how to verify that cache entries are removed after eviction methods execute.
Verify before relying
Read SKILL.md below before installing (1 file). Open directory: indexed for reading, not audited.
Install
giuseppe-trisciuoglio/developer-kit/unit-test-caching · repository language: Python
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How do I unit test Spring @Cacheable annotation?
unit-test-caching teaches you to isolate @Cacheable behavior by injecting a ConcurrentMapCacheManager into your test, then verifying cache hits by checking that your repository method is called fewer times than the number of invocations. Use Mockito's times() matcher to assert call counts and confirm the cache prevented redundant database queries.
How can unit-test-caching help verify cache hit/miss behavior?
unit-test-caching provides patterns to verify cache hit/miss by counting repository invocations with Mockito.verify(). For cache hits, the repository is called once but the method is invoked multiple times; for misses, call counts match invocation counts. This skill shows how to assert these patterns without requiring Redis or external cache infrastructure.
What does unit-test-caching teach about testing @CacheEvict invalidation?
unit-test-caching covers @CacheEvict testing by demonstrating how to verify that cache entries are removed after eviction methods execute. You'll learn to check that subsequent calls to the cached method trigger repository calls again, confirming the cache was actually cleared rather than returning stale data.
Can unit-test-caching help test cache key generation from SpEL expressions?
Yes. unit-test-caching includes patterns for testing SpEL-based cache keys and compound keys by verifying that different parameter combinations produce distinct cache entries. You'll learn to mock CacheManager and inspect cache contents to confirm key generation logic works correctly without needing complex integration tests.
How does unit-test-caching address conditional caching with unless/condition?
unit-test-caching teaches you to mock cache managers and test conditional caching by verifying that @Cacheable with unless or condition attributes correctly skips caching when predicates are false. You'll use Mockito to confirm the cache.get() method is never called for excluded conditions, validating your conditional logic in isolation.
What patterns does unit-test-caching provide for null result handling?
unit-test-caching covers null result handling by showing how to test @Cacheable and @CachePut behavior when methods return null. You'll learn whether your cache stores null values and how to validate cache eviction strategies that may treat nulls differently, ensuring your application handles edge cases consistently.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
Unit Testing Spring Caching
Overview
This skill provides patterns for unit testing Spring caching annotations (@Cacheable, @CacheEvict, @CachePut) without full Spring context. It covers cache hits/misses, invalidation, key generation, and conditional caching using in-memory ConcurrentMapCacheManager.
When to Use
- Writing unit tests for
@Cacheablemethod behavior - Verifying
@CacheEvictcache invalidation works correctly - Testing
@CachePutcache updates - Validating cache key generation from SpEL expressions
- Testing conditional caching with
unless/conditionparameters - Mocking cache managers in fast unit tests without Redis
(truncated - see the full file via the links below)
File tree — 1 file
plugins/developer-kit-java/skills/unit-test-caching/SKILL.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Write unit tests for Spring @Cacheable, @CacheEvict, @CachePut annotations”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
Build reliable unit tests for Java applications using JUnit 5, Mockito, and AssertJ with support for mocking, parameterized tests, and fluent assertions. Includes integration testing patterns with Testcontainers and Spring Boot Test, plus TDD and test coverage best practices to improve code quality.
Master isolated service layer testing using Mockito to mock repositories and external clients without database or API calls. This skill teaches you to arrange test data, verify method interactions, and handle exception scenarios with AssertJ assertions.
This skill teaches patterns for unit testing Spring ApplicationEvent publishers and @EventListener consumers using JUnit 5 and Mockito, without booting the full Spring context. Learn to mock ApplicationEventPublisher, capture events with ArgumentCaptor, verify listener side effects, and test async event handling. Covers error scenarios and best practices for keeping event tests isolated and deterministic.
Spring Boot Test Patterns guides you through layered testing strategies—from fast unit tests with mocked dependencies to full integration tests with real databases via Testcontainers. Learn focused slice testing with @DataJpaTest and @WebMvcTest, REST API testing with MockMvc, and container setup using @ServiceConnection for Spring Boot 3.5+.
Automatically generate well-structured JUnit 5 test cases for Java classes, complete with Mockito mocking, parameterized test scenarios, and edge case handling. The skill follows Arrange-Act-Assert patterns, creates tests for exception handling, verifies mock interactions, and targets high test coverage across service layers and Spring Boot components.
Cc Java Dev provides comprehensive Java coding standards and best practices, including naming conventions, class member ordering, DTO specifications, and batch query optimization. It covers critical patterns like N+1 query prevention, concurrent safety with atomic updates and optimistic locking, and Spring Boot conventions for dependency injection and transaction management. The skill includes input validation rules, exception handling strategies, and test specifications to help developers write maintainable, performant Java applications.
More skills testing (MIT) · unit-test-controller-layer (MIT)