2

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

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

4

1 回答 1

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
于 2011-06-12T20:08:50.960 回答