单元测试轨道时的 ActiveSupport::TestCase 与 Test::Unit::TestCase
我最近注意到,如果我的测试子类 Test::Unit::TestCase,我的测试数据库在运行后没有被清理。如果我的测试子类为 ActiveSupport::TestCase,则所有内容都会正确清理。
谁能解释为什么,和/或提供使用其中一种与另一种的解释?
我正在使用shoulda和factory_girl。
谢谢。
I recently noticed my test database is not being cleaned up after my tests run if my tests subclass Test::Unit::TestCase. If my tests subclass ActiveSupport::TestCase, everything is cleaned up properly.
Can anyone explain why, and/or provide an explanation of using one versus the other?
I am using shoulda and factory_girl.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看代码,你会看到
ActiveSupport::TestCase
有很多用于测试 Rails 的设置和实用函数。旧版本的 Rails 曾经使用Test::Unit::TestCase
和大量 mixin,但不久前转向了子类化。如果您正在测试 Rails 应用,则应该为控制器创建
ActiveSupport::TestCase
或ActionController:TestCase
子类。生成器会自动执行此操作,因此大多数时候您不必考虑它。If you take a look at the code, you'll see
ActiveSupport::TestCase
has a lot of of setup and utility functions for testing Rails. Older versions of Rails used to useTest::Unit::TestCase
with a lot of mixins, but moved to subclassing a while ago.If you're testing a Rails app, you should subclass
ActiveSupport::TestCase
orActionController:TestCase
for controllers. The generators will do this automatically, so you should not have to think about it most of the time.