0
目前,我的一个测试函数有8个断言。如果第一个失败,它跳过剩下的断言并进入下一个功能。这种行为如何改变?MiniTest:在断言失败时不应跳过函数
目前,我的一个测试函数有8个断言。如果第一个失败,它跳过剩下的断言并进入下一个功能。这种行为如何改变?MiniTest:在断言失败时不应跳过函数
总之:你不能。
我假设你有这样的事情:
def test_foo
assert_equal 0, Foo.calculate(nil)
assert_equal 0, Foo.calculate()
assert_equal 12, Foo.calculate(8, 4)
assert_equal 0, Foo.calculate(4, -4)
...
end
很多断言的单个测试方法中。你可以做的就是这种分成多个测试方法:
def test_result_when_input_is_nil
assert 0, Foo.calculate(nil)
end
def test_result_when_no_input
assert 0, Foo.calculate()
end
def test_calculates_result
assert 12, Foo.calculate(8, 4)
end
def test_can_handle_negative_numbers
assert 0, Foo.calculate(4, -4)
end
你从此得到更好的错误信息,因为它是明确的,当东西坏了,并在那里分手。
您认为该如何表现?请粘贴测试。 – medik