如何使用 Test::Unit 在一组测试中切换 transactional_fixtures 的使用?
我有一些 Thinking-sphinx 测试,我需要关闭事务以防止 mysql 锁定,但这样做会破坏以前编写的许多其他测试,因此我需要能够切换设置。
我发现了有关 rspec 的类似问题,但对于 Test::Unit 没有。
我尝试过 self.use_transactional_fixtures = false ,这使得 sphinx 测试能够通过,但会导致其他测试失败。我确信我可以在所有其他测试中将其设置为 true,但这也需要所有其他测试也包含代码片段,这很混乱。
我也尝试过 uses_transaction :test_method_name
,但其工作原理与前面提到的方法相同。
预先感谢您的任何帮助。
I have some thinking-sphinx tests that I need to turn off transactions for to prevent mysql locks, but in doing so I break a lot of other tests previously written, so I need to be able to toggle the setting.
I have found similar questions regarding rspec, but none for Test::Unit.
I have tried self.use_transactional_fixtures = false
which is what allows the sphinx tests to pass, but causes others to break. I am sure I could set that to true in all the other tests, but that would also require all other tests to include the code snippet as well which is messy.
I have also tried uses_transaction :test_method_name
, but that works the same as the previously mentioned method.
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够仅针对您拥有的 sphinx 相关测试将 use_transactional_fixtures 设置为 false,但对于您拥有的其他测试将其保留为 true。关键是将您的测试分成单独的测试类。因此,在 test_helper.rb 中,您仍然会拥有:
但对于其他测试,您将执行类似的操作
这应该意味着您的常规测试使用快速事务装置运行,但 Rails 将根据需要使用 DELETE / INSERT 方法。
You should be able to set use_transactional_fixtures to false for just the sphinx related tests that you have, but leave it true for the other tests you have. The key will be to split your tests into separate test classes. So in test_helper.rb you'll still have:
But then for your other tests you'll do something like
That should mean that your regular tests run using the fast transactional fixtures, but rails will use the DELETE / INSERT method as required.
您还可以使用 uses_transaction 禁用它们具体方法/测试。
You can also use uses_transaction to disable them for specific method/test.