这里就是我有我将如何正确构建此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