【发布时间】:2014-10-12 20:24:02
【问题描述】:
我刚开始使用 SpecFlow,非常喜欢这个工具。但是,我遇到了与场景大纲中的示例数据输入相关的一些问题。
只是想知道我所面对的是否正常或是否有技巧。
我正在使用 C# Visual Studio 2013 并使用下划线样式的步骤定义编写 MVC 应用程序。我也尝试过正则表达式样式,但仍然遇到类似的问题。
所以问题是我提供用户名、密码等作为参数,并在我的示例中包含示例数据。似乎发生了以下情况:-
在第一次生成场景时,我必须在参数周围加上“”,否则它根本不会作为参数被拾取。但是,当从示例中传入数据时,我在传入的数据末尾得到一个“/”。当我回到场景时,我删除了参数周围的“”。这有点令人沮丧,但如果这是处理它的最佳方式,我可以忍受。只是想知道是否有人对此有任何建议。
下一个问题与数据本身有关。如果我的数据中有任何字符,例如 @ 或 & 等,那么它会在该点拆分该数据并将其提供给下一个参数,这样我就会得到不正确的数据。
我在下面包含了我的代码 - 如果有人有任何建议或资源可以查看,我们将不胜感激。
功能文件 功能:帐户注册 为了在我的组织中使用 Mojito 服务 作为访客用户 我想创建一个具有管理权限的帐户
Scenario Outline: Register with valid details
Given I am on the registration page
And I have completed the form with <email> <organisation> <password> and <passwordConfirmation>
When I have clicked on the register button
Then I will be logged in as <username>
And my account will be assigned the role of <role>
Examples:
| email | organisation | password | passwordConfirmation | username | role |
| usernamea | Bytes | password1 | password1 | usernamea | Admin |
| usernameb | Bytes | password2 | password2 | usernameb | Admin |
| usernamec | Bytes | password3 | password3 | usernamec | Admin |
| usernamed | Bytes | password4 | password4 | usernamed | Admin |
| usernamee | Bytes | password5 | password5 | usernamee | Admin |
Scenario Outline: Register with invalid details
Given I am on the registration page
And I have completed the form with <email> <organisation> <password> and <passwordConfirmation>
When I have clicked on the register button
Then I will get an error message
Examples:
| email | organisation | password | passwordConfirmation |
| Jonesa@mojito.com | Bytes | 1LTIuta&Sc | wrongpassword |
| Jonesb@mojito.com | Bytes | 1LTIuta&Sc | 1LTIuta&Sc |
| Jonesc@mojito.com | No Organisation | 1LTIuta&Sc | 1LTIuta&Sc |
步骤生成文件
[Binding]
public class AccountRegistrationSteps
{
[Given]
public void Given_I_am_on_the_registration_page()
{
ScenarioContext.Current.Pending();
}
[Given]
public void Given_I_have_completed_the_form_with_usernamea_Bytes_password_P0_and_password_P1(int p0, int p1)
{
ScenarioContext.Current.Pending();
}
[Given]
public void Given_I_have_completed_the_form_with_Jonesa_mojito_com_Bytes_P0_LTIuta_Sc_and_wrongpassword(int p0)
{
ScenarioContext.Current.Pending();
}
[When]
public void When_I_have_clicked_on_the_register_button()
{
ScenarioContext.Current.Pending();
}
[Then]
public void Then_I_will_be_logged_in_as_usernamea()
{
ScenarioContext.Current.Pending();
}
[Then]
public void Then_my_account_will_be_assigned_the_role_of_Admin()
{
ScenarioContext.Current.Pending();
}
[Then]
public void Then_I_will_get_an_error_message()
{
ScenarioContext.Current.Pending();
}
}
【问题讨论】:
标签: c# asp.net-mvc specflow acceptance-testing gherkin