這裏就是我有我將如何正確構建此SpecFlow功能/場景設置?
Feature: Register a new customer
As a user
I need to be able to register myself
so that I can place orders
Scenario: Register a new customer with Valid information
Given I fill in valid customer information
When I press submit
Then I should be notified that I'm registered
Scenario: Register a new customer with Invalid information
Given I fill in invalid customer information
When I press submit
Then I should be notified it was invalid
的問題是,我重複兩次當,但我沒有看到解決的辦法,我需要做的是找出你將如何進行此項設置正確使用2個場景或者我沒有正確看待這個?
以下是步驟定義,但它們對我來說似乎不太合適,因爲我必須將它們放在相同的Steps類中才能運行。在我看來,沒有正確閱讀。當我將這兩部分分開並將它們放在他們自己的步驟課程中時,我得到了這個錯誤:
binding error: Ambiguous step definitions found for step 'When I press submit':
[Binding]
public class RegisterAValidCustomerSteps
{
private RegisterCustomerViewModel _registerCustomerVm;
[Given(@"I fill in valid customer information")]
public void GivenIFillInValidCustomerInformation()
{
// use the ViewModel to represent the User interacting with the View
_registerCustomerVm = new RegisterCustomerViewModel();
_registerCustomerVm.FirstName = "Mark";
_registerCustomerVm.LastName = "W";
_registerCustomerVm.Email = "[email protected]";
}
[Given(@"I fill in invalid customer information")]
public void GivenIFillInInvalidCustomerInformation()
{
// simulate possible invalid name by missing the Last Name
_registerCustomerVm = new RegisterCustomerViewModel();
_registerCustomerVm.FirstName = "Mark";
_registerCustomerVm.Email = "[email protected]";
}
[When(@"I press submit")]
public void WhenIPressSubmit()
{
_registerCustomerVm.Submit();
}
[Then(@"I should be notified that I'm registered")]
public void ThenIShouldBeAbleToPlaceOrders()
{
_registerCustomerVm.MessageText.ShouldBe("Success! Check your inbox for confirmation");
}
[Then(@"I should be notified it was invalid")]
public void ThenIShouldBeNotifiedItWasInvalid()
{
_registerCustomerVm.MessageText.ShouldBe("Failure! Last Name can't be blank.");
}
}
好吧,對於我的情況,我應該真的有一個鑑於「鑑於我填寫我的註冊名稱和電子郵件」和2和聲明「和信息是有效的」,「信息是無效的」,「當我按提交「,然後2條語句正確?也是所有這些在一個步驟課內? – 2012-04-26 22:15:10
其實你可以有一個給定的步驟'給我填寫註冊表格'與specflow表格描述輸入數據。但我寧願用兩個不同的步驟(如現在這樣)來描述輸入的數據類型(有效或無效)。在準備上下文之後,你有一個'當我提交註冊表單時'(我認爲它更接近業務,然後'當我按Submit時')。然後是兩個步驟,就像現在一樣。 – 2012-04-26 22:24:33