HermanD の回答に関しては、これは Ruby であるため、クラスで直接これを実行して、独自のテスト メソッドを作成することもできます。
class MyObjectTest < Test::Unit::TestCase
[
{:param => 1, :expected => 'whatever is expected'},
{:param => 2, :expected => 'whatever is expected'},
{:param => 3, :expected => 'whatever is expected'},
{:param => 4, :expected => 'whatever is expected'},
{:param => 5, :expected => 'whatever is expected'},
{:param => 6, :expected => 'whatever is expected'}
].each do |test_case|
define_method :"test_using_#{test_case[:param]}_should_return_#{params[:expected].underscore}" do
assert_equal test_case[:expected], MyObject.new.do_something_with(test_case[:param])
end
end
end
Rspec (または Shoulda) の文のような言語を使用すると、さらに自然に感じられます。
describe MyObject do
[
{:param => 1, :expected => 'whatever is expected'},
{:param => 2, :expected => 'whatever is expected'},
{:param => 3, :expected => 'whatever is expected'},
{:param => 4, :expected => 'whatever is expected'},
{:param => 5, :expected => 'whatever is expected'},
{:param => 6, :expected => 'whatever is expected'}
].each do |test_case|
it "should return #{test_case[:expected]} when using #{test_case[:param]}" do
MyObject.new.do_something_with(test_case[:param]).should == test_case[:expected]
end
end
end