| In general, code that is marked with cache related annotations can be unit |
| tested without doing anything special to deal with caching. The caching just |
| won't be enabled and the code in cached methods will be executed each time the |
| method is invoked. |
| |
| [source,groovy] |
| ---- |
| include::{sourcedir}/grails-app/services/com/demo/BasicCachingService.groovy[tags=get_data,indent=0] |
| ---- |
| |
| [source,groovy] |
| ---- |
| include::{sourcedir}/src/test/groovy/com/demo/BasicCachingServiceNoCacheManagerSpec.groovy[] |
| ---- |
| |
| In order for caching to be active when the unit test is running, cache manager |
| and key generator beans must be added to the Spring application context by the |
| test. |
| |
| [source,groovy] |
| ---- |
| include::{sourcedir}/src/test/groovy/com/demo/BasicCachingServiceSpec.groovy[] |
| ---- |