OverviewHistoryStatsSecurity
npx skills add ...
Documentation
SKILL.md
npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-caching
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.
npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-caching
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.
@Cacheable method behavior@CacheEvict cache invalidation works correctly@CachePut cache updatesunless/condition parametersConcurrentMapCacheManager for tests@BeforeEachtimes(n) assertions to confirm cache behavior@CacheEvict, verify repository called again on next readunless (null results) and condition (parameter-based)Validation checkpoints:
@EnableCaching annotation presentthis calls)@Cacheable(key="...") expression@Cacheable (Cache Hit/Miss)@CacheEvict@CachePutverify(mock, times(n)) to assert cache behaviorConcurrentMapCacheManager: Fast, no external dependencies@CacheEvict actually invalidates cached data@Cacheable requires proxy: Direct method calls (this.method()) bypass caching - use dependency injectionunless = "#result == null" to exclude@CachePut always executes: Unlike @Cacheable, it always runs the methodConcurrentMapCacheManager is thread-safe; distributed caches may require additional config| Issue | Solution |
|---|---|
| Cache not working | Verify @EnableCaching on test config |
| Proxy bypass | Use autowired/constructor injection, not direct this calls |
| Key mismatch | Log cache key with cache.getNativeKey() to debug SpEL |
| Flaky tests | Clear cache in @BeforeEach before each test |