【问题标题】:Checking for test result in Ruby test/unit teardown method在 Ruby 测试/单元拆解方法中检查测试结果
【发布时间】:2011-06-12 19:53:38
【问题描述】:

是否可以在拆解方法中检查 Ruby 测试/单元的结果?

我正在使用带有 Test/Unit、WATIR 和 Webdriver 的 Ruby 来测试 Web 应用程序,如果测试失败,我想在拆卸方法中截取屏幕截图。

【问题讨论】:

    标签: ruby watir testunit watir-webdriver


    【解决方案1】:

    改为更改 assert_equal(或您正在使用的任何断言)怎么样?

    require 'test/unit'
    
    class Test::Unit::TestCase
      def assert_equal(expected, got, msg)
        begin
          super(expected, got, msg)
        rescue
          p "caught ya!" # make screenshot here
          raise
        end
      end
    end
    
    class DemoTest < Test::Unit::TestCase
    
      def test_fail
        assert_equal(1, 0, 'ups')
      end
    end
    

    【讨论】:

    • 感谢这可能是一个可行的解决方案,因为我在测试中主要使用 assert 和 assert_equal。
    猜你喜欢
    • 2010-09-07
    • 2015-11-19
    • 1970-01-01
    • 2021-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多