【发布时间】:2023-03-29 02:47:02
【问题描述】:
是否可以(从概念上)在测试方法中运行 for 循环?
我想在控制器中测试一系列参数值,以确定不同的输入是否返回正确的值。
test "logged in user - add something - 0 qty" do
@app = Factory.create(:app)
(0..5).each do |t|
@qty = t
login(:user)
get :add. :id => @app.id, :qty => @qty
assert_nil(flash[:error])
assert_response :redirect
assert_redirect_to :controller => :apps, :action => :show, :id => @app.id
if @qty = 0
assert_equal(Invite.all.count, @qty + 1)
else
assert_something .........
end
end
类似的东西。
【问题讨论】:
-
顺便说一句,我碰巧在一个项目中工作,我们有一个完整的测试套件,其中每个测试用例都有一个循环。 (该套件测试 Tracemonkey,一个只编译热循环的 JIT。);)
标签: ruby-on-rails ruby unit-testing functional-testing