即使认为某些断言失败,assert_equal还能继续运行吗?

时间:2015-04-30 06:29:12

标签: ruby

我通过assert_equal循环遍历一行值,如下所示:

assert_equal(test[i][4].to_i, featureOne(test[i][1], test[i][2]),test[i][0])

我只是想知道assert_equal是否设计为在测试失败时第1​​次停止?

例如,如果第二次测试失败,其余的测试将不会被执行?

是否有任何我可以使用的库继续进行下一次测试但是当前的测试失败了?

1 个答案:

答案 0 :(得分:0)

当然不是,如果第二次测试失败,其余测试将被执行。我给你举个例子:

class Test
  def add a, b
    a + b
  end
  def minus a, b
    a - b
  end
end

require "minitest/autorun"
class TestTest < Minitest::Unit::TestCase

  def test_ad
    a = Test.new
    assert_equal 2, a.add(1,1)
    assert_equal 2, a.add(1,2)
  end

  def test_minus
    a = Test.new
    assert_equal 0, a.minus(1,1)
    assert_equal 2, a.minus(1,2)
  end

end

您将获得输出:

Run options: --seed 61427

# Running:

FF

Finished in 0.001360s, 1470.5223 runs/s, 2941.0446 assertions/s.

  1) Failure:
TestTest#test_ad :
Expected: 2
  Actual: 3


  2) Failure:
TestTest#test_minu :
Expected: 2
  Actual: -1

2 runs, 4 assertions, 2 failures, 0 errors, 0 skips