考慮下面的代碼:Specflow表列綁定防止空值
public class Bob {
public string Name { get; set; }
public int Age { get; set; }
public decimal Height { get; set; }
}
Feature: Bob checker
Scenario: Check Bob
Given I have the following Bob
| Name | Age | Hieght |
| Robert | 63 | 1.87 |
When . . . .
Then . . . .
[Given(@"I have the following Bob")]
public void IHaveTheFollowingBob(Table table) {
var bob = table.CreateInstance<Bob>();
}
You'l注意單詞「身高」沒有在表中拼寫正確。 CreateInstance
方法仍然可以工作,但Bob對象上的「高度」將爲0或引用類型爲null。
如果列未綁定到所提供的類型,是否有方法使SpecFlow失敗?謝謝
如何使用CompareToInstance(..),因爲您沒有您嘗試在步驟中創建的實例?如果你拋出一個虛擬實例,比較會拋出一個異常。 – valentinvs
@valentinvs只是編輯答案更完整。 – jolySoft