4
我想知道Rspec中的命令步驟和聲明步驟是什麼。Rspec中的命令步驟和說明步驟
下面是來自Rspec的書的示例代碼:
Scenario: transfer money (declarative)
Given I have $100 in checking
And I have $20 in savings
When I transfer $15 from checking to savings
Then I should have $85 in checking
And I should have $35 in savings
Scenario: transfer money (imperative)
Given I have $100 in checking
And I have $20 in savings
When I go to the transfer form
And I select "Checking" from "Source Account"
And I select "Savings" from "Target Account"
And I fill in "Amount" with "15"
And I press "Execute Transfer"
Then I should see that I have $85 in checking
And I should see that I have $35 in savings
我不太明白了。
我的理解是,只要結果通過,聲明式讓你做任何你想做的事情,而且命令更加冗長。
但是,我不覺得我已經明白了這一點。
有人可以解釋這一點多一點。有什麼區別,我應該選擇哪一個?
耦合問題的好例子,但是當您使用驗收測試來定義用戶故事中的預期內容時,明確定義這些步驟非常重要。聲明性步驟隱藏了http://en.wikipedia.org/wiki/Specification_by_example所需的詳細信息。 https://github.com/cheezy/page-object看起來像是一個很好的開始,以解決UI耦合而不犧牲所需的細節。 – Brenden 2013-10-18 00:18:48
我發現BDD最適合捕捉對話,而不是完全指定UI交互。這是Dan首先提出「測試」一詞的原因之一。不過,請同意使用頁面對象範例。 – Lunivore 2013-10-19 09:41:41