0
我有一個長表單,並且對於3個字段,我需要測試它們是單獨填寫正確還是錯誤,因爲錯誤會導致非常不同的操作。但它是非常繁瑣和不幹燥寫集成測試是這樣的:測試冗長的表格,而無需每次都重寫所有fill_ins
# Test 1
describe "test where field3 fails" do
before do
fill_in "field1", with: "passing info"
fill_in "field2", with: "passing info"
fill_in "field3", with: "not passing info"
...
end
it "should lead to an error specific to field3" do
...
end
end
# Test 2
describe "test where field2 fails" do
before do
fill_in "field1", with: "passing info"
fill_in "field2", with: "not passing info"
fill_in "field3", with: "passing info"
...
end
it "should lead to an error specific to field2" do
...
end
end
# Test 3
describe "test where field1 fails" do
before do
fill_in "field1", with: "not passing info"
fill_in "field2", with: "passing info"
fill_in "field3", with: "passing info"
...
end
it "should lead to an error specific to field1" do
...
end
end
我喜歡使用散列的想法!但挑戰並不是每個字段都是'fill_in',有些是'check',有些甚至是'page.execute_script'。但是你讓我想知道我是否可以在散列中存儲整行代碼:例如,散列看起來像'{code:'fill_in'field1',其中''傳遞數據'',結果:「錯誤消息」} '。如果我這樣做,有沒有辦法讓代碼評估爲一行代碼而不是字符串? – james
整個想法是保持代碼簡單,並與測試數據組合分離。您可以擁有任何類型的字段,但會根據提供的數據採取行動.Ex:要選擇的複選框可以作爲來自測試數據的Y/N提供可以保存在外部的csv/xml /文本文件中。 –
我的想法很簡單,就是使用數組驅動測試並運行多次迭代。 –