代码之家  ›  专栏  ›  技术社区  ›  chris

一个人如何使用test::Unit为一组测试切换事务性\u设备的使用?

  •  1
  • chris  · 技术社区  · 15 年前

    我有一些想法斯芬克斯测试,我需要关闭事务来防止MySQL锁,但这样做,我打破了以前编写的许多其他测试,所以我需要能够切换设置。

    我发现了类似的问题 rspec ,但测试::单元没有。

    我试过了 self.use_transactional_fixtures = false 这使得狮身人面像测试得以通过,但也导致其他测试失败。我确信我可以在所有其他测试中将其设置为真,但这也需要所有其他测试也包括代码片段,这很混乱。

    我也试过了 uses_transaction :test_method_name ,但其工作原理与前面提到的方法相同。

    事先谢谢你的帮助。

    2 回复  |  直到 10 年前
        1
  •  4
  •   NZKoz    15 年前

    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
    

        2
  •  1
  •   Vlado Cingel    10 年前

    uses_transaction

    class MyTest < ActiveSupport::TestCase
    
      uses_transaction :test_something
      test "something" do
        "test something like callback"
      end
    
    end