编写单元/功能测试时考虑缓存

发布于 2024-12-10 15:25:40 字数 232 浏览 0 评论 0原文

我正在 Ruby on Rails 应用程序中编写单元和功能测试。每当有人对我提出缺陷时,我都会尝试编写测试。最近出现的缺陷之一与我们如何更新对象的缓存或使其无效直接相关。编写测试时考虑缓存是否正常?我还没有看到太多这样的事情,但现在很多东西都存储在 Redis 或 Memcached(我们使用 Redis)等工具中。我认为对从这些内存存储中存储/检索的任何内容进行测试也需要进行测试。在 Rails 3 中是否可以提供任何工具或建议来实现这一点?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江南月 2024-12-17 15:25:40

缓存应该在集成级别进行测试,特别是当您有多个缓存层一起工作时,因为它可能很复杂。您还可以编写较低级别的单元测试来验证对象应被标记为过时的条件。

为了修复缺陷,我建议首先尝试编写一个重现错误的集成测试,然后针对适当的类进行单元测试。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文