如何使用 Test::Unit 在一组测试中切换 transactional_fixtures 的使用?

发布于 2024-09-30 00:35:58 字数 477 浏览 5 评论 0原文

我有一些 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 技术交流群。

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

发布评论

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

评论(2

无所的.畏惧 2024-10-07 00:35:58

您应该能够仅针对您拥有的 sphinx 相关测试将 use_transactional_fixtures 设置为 false,但对于您拥有的其他测试将其保留为 true。关键是将您的测试分成单独的测试类。因此,在 test_helper.rb 中,您仍然会拥有:

self.use_transactional_fixtures = true

但对于其他测试,您将执行类似的操作

class PostTest < ActiveSupport::TestCase
  # your normal post tests that require transactional fixtures
end

class SphinxRelatedPostTest < ActiveSupport::TestCase
  self.use_transactional_fixtures = false
  # your other tests
end

这应该意味着您的常规测试使用快速事务装置运行,但 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:

self.use_transactional_fixtures = true

But then for your other tests you'll do something like

class PostTest < ActiveSupport::TestCase
  # your normal post tests that require transactional fixtures
end

class SphinxRelatedPostTest < ActiveSupport::TestCase
  self.use_transactional_fixtures = false
  # your other tests
end

That should mean that your regular tests run using the fast transactional fixtures, but rails will use the DELETE / INSERT method as required.

寻梦旅人 2024-10-07 00:35:58

您还可以使用 uses_transaction 禁用它们具体方法/测试。

class MyTest < ActiveSupport::TestCase

  uses_transaction :test_something
  test "something" do
    "test something like callback"
  end

end

You can also use uses_transaction to disable them for specific method/test.

class MyTest < ActiveSupport::TestCase

  uses_transaction :test_something
  test "something" do
    "test something like callback"
  end

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