gpt4 book ai didi

Ruby 测试 :Unit, 如何知道测试套件中每个测试用例的失败/通过状态?

转载 作者:行者123 更新时间:2023-11-28 20:33:02 25 4
gpt4 key购买 nike

这个问题听起来很愚蠢,但我从来没有在网上找到答案。假设您有一个像这个页面这样的测试套件: http://en.wikibooks.org/wiki/Ruby_Programming/Unit_testing或代码:

require "simpleNumber"
require "test/unit"

class TestSimpleNumber < Test::Unit::TestCase

def test_simple
assert_equal(4, SimpleNumber.new(2).add(2) )
assert_equal(4, SimpleNumber.new(2).multiply(2) )
end

def test_typecheck
assert_raise( RuntimeError ) { SimpleNumber.new('a') }
end

def test_failure
assert_equal(3, SimpleNumber.new(2).add(2), "Adding doesn't work" )
end

end

运行代码:

>> ruby tc_simpleNumber2.rb
Loaded suite tc_simpleNumber2
Started
F..
Finished in 0.038617 seconds.

1) Failure:
test_failure(TestSimpleNumber) [tc_simpleNumber2.rb:16]:
Adding doesn't work.
<3> expected but was
<4>.

3 tests, 4 assertions, 1 failures, 0 errors

现在,如何使用变量(什么样的?)来保存测试结果?例如,像这样的数组:

[{:name => 'test_simple', :status => :pass}, 
{:name => 'test_typecheck', :status => :pass},
{:name => 'test_failure', :status => :fail},]

我是测试新手,但很想知道答案...

最佳答案

你需要执行你的测试脚本文件,仅此而已,结果将显示通过或失败。

假设你保存文件test_unit_to_rspec.rb,然后执行下面的命令

ruby test_unit_to_rspec.rb

关于Ruby 测试 :Unit, 如何知道测试套件中每个测试用例的失败/通过状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9477493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com