unit-test-caching

Solid

Provides patterns for unit testing Spring Cache annotations (@Cacheable, @CachePut, @CacheEvict). Generates test code that mocks cache managers, verifies cache hit/miss behavior, tests cache key generation with SpEL expressions, validates eviction strategies, and checks conditional caching scenarios. Triggers: caching tests, test Spring cache, mock cache, Spring Boot caching, cache hit/miss verification, @Cacheable testing.

Testing & QA 278 stars 32 forks Updated 5 days ago MIT

Install

View on GitHub

Quality Score: 91/100

Stars 20%
81
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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 `@Cacheable` method behavior - Verifying `@CacheEvict` cache invalidation works correctly - Testing `@CachePut` cache updates - Validating cache key generation from SpEL expressions - Testing conditional caching with `unless`/`condition` parameters - Mocking cache managers in fast unit tests without Redis ## Instructions 1. **Configure in-memory CacheManager**: Use `ConcurrentMapCacheManager` for tests 2. **Set up test fixtures**: Mock repository and create service instance in `@BeforeEach` 3. **Verify repository call counts**: Use `times(n)` assertions to confirm cache behavior 4. **Test cache hit**: Call method twice, verify repository called once 5. **Test cache miss**: Verify repository called on each invocation 6. **Test eviction**: After `@CacheEvict`, verify repository called again on next read 7. **Test key generation**: Verify compound keys from SpEL expressions 8. **Validate conditional caching**: Test `unless` (null results) and `condition` (parameter-based) **Validation checkpoints:** - Run test → If cache not working: verify `@EnableCaching` annotation present - If proxy issues: ensure method calls go throug...

Details

Author
giuseppe-trisciuoglio
Repository
giuseppe-trisciuoglio/developer-kit
Created
7 months ago
Last Updated
5 days ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category