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.
SkillScore91Maintained
Automatic
◆Coding pack
Last verified 8/21/2026
What it changes
Passed 20 of 22 test cases with the skill, and 18 of 22 without it.
Without skill82%
With skill91%
Checks it passed that the model alone missed
Verify repository is called again for multiple distinct keys after clearing all entries
Instantiate the service and repository mocks without Spring Boot test context annotations
2 fixed18 passed either way2 still failing0 broke
Pass-rate lift
+9 pp
Tokens
+105%
Agent turns
0%
Response time
-32%
Model gemini-3.6-flashMeasured 8/21/2026v120 of 22 cases passed with skill
Tokens, turns and time describe resource use, not a dollar price.
See it in action
One of 2 test cases the skill fixed. Same model, same prompt, with and without the skill.
1 of 2
Prompt
We are implementing cache invalidation in our Spring application using `@CacheEvict` when deleting products. I need to write a unit test verifying that calling the delete method removes the item from the cache, so that the next read query actually triggers the repository again. Please show me a complete Java test example verifying this cache eviction workflow.
What was checked, without and with the skill
Checked
Without skill
With skill
Verify that the underlying repository read operation executes a second time after eviction
Passed
Passed
Instantiate the service and repository mocks without Spring Boot test context annotations
Missed
Passed
case-02 · gemini-3.6-flash · 8/21/2026 · answers are capped and redacted
What's inside
The instructions your model reads when the skill loads.
SKILL.md354 linessingle file
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
Configure in-memory CacheManager: Use ConcurrentMapCacheManager for tests
Set up test fixtures: Mock repository and create service instance in @BeforeEach
Verify repository call counts: Use times(n) assertions to confirm cache behavior
Test cache hit: Call method twice, verify repository called once
Test cache miss: Verify repository called on each invocation
Test eviction: After @CacheEvict, verify repository called again on next read
Test key generation: Verify compound keys from SpEL expressions
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 through Spring proxy (no direct this calls)
If key mismatches: log actual cache key and compare with @Cacheable(key="...") expression