I am writing unit and functional tests in my Ruby on Rails application. I try to write a test anytime someone opens a defect against me. One of the defects that recently came up was directly related to either how we are updating the cache for an object or invalidating it. Is it normal to take caching into consideration when writing tests? I have not seen it done for much, but these days so much is stored in tools such as Redis or Memcached (we use Redis). I think testing for anything that gets stored/retrieved from these in-memory stores needs to also be in tests. Are there any tools or advice one could give for doing that in Rails 3?
Share
Caching should be tested at the integration level, especially if you have multiple layers of caching working together, as it can be complex. You can also write lower-level unit tests to verify the conditions under which an object should be marked as stale.
For fixing defects, I would suggest first trying to writing an integration test which reproduces the bug, and then a unit test for the appropriate class.