27. 27
小明也學到了TDD的三個重要原則
• UncleBob: http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd
1. You are not allowed to write any production code unless it is to make a failing unit test pass.
在有一個錯誤的測試之前不應該撰寫任何production code
2. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation
failures are failures.
當有一個失敗的測試案例(編譯錯誤也是錯誤)時,不應該撰寫更多的測試案例
3. You are not allowed to write any more production code than is sufficient to pass the one
failing unit test.
除了足夠通過測試案例的程式碼以外不應該撰寫更多額外的程式碼
41. • 用人話描述需求─Gherkin語法:
Feature: 用一個簡單的故事描述需求
Scenario: 系統行為
Given – Arrange
When – Act
Then – Assert
41
Sample
Feature:
In order to 避免計算錯誤
As a 數學白癡
I want to 知道兩個數字相加的結果
Scenario: 兩個數字相加
Given 在計算機輸入 50
And 按下 + 按鈕
And 在計算機輸入70
When 按下計算
Then 結果應該為 120
在BDD中,用人話搭配Gherkin語法描述需求規格