C# 在BeforeTestRun Hook-Specflow中创建具有不同变量的多个用户的最佳方法
嗨,我有个问题 目前我正在C# 在BeforeTestRun Hook-Specflow中创建具有不同变量的多个用户的最佳方法,c#,cucumber,specflow,C#,Cucumber,Specflow,嗨,我有个问题 目前我正在users位置下创建一个用户,我还想在admin位置下创建一个用户 我的Specflow场景如下所示 @createUser Scenario Outline: Do Something to created users Given A user has already been created under <location> When I do something with the user Then I expected som
users
位置下创建一个用户,我还想在admin
位置下创建一个用户
我的Specflow场景如下所示
@createUser
Scenario Outline: Do Something to created users
Given A user has already been created under <location>
When I do something with the user
Then I expected something to happen
Examples:
| location |
| admin |
| users |
我只希望在执行开始时创建一次用户,并在执行结束时清理它们,上面的场景只是我复杂场景的简化版本
我还有多个场景将在不同的位置使用这两个不同的用户
将来还会添加更多的位置,因此我希望将表变量作为参数传递到BeforeTestRun钩子中,到目前为止我还没有成功,也不确定是否可以使用specflow,而且我相信可能会有更好的解决方案,我希望尽可能避免重复
任何想法/帮助都将不胜感激
Given there is an admin user
And there is a user
这是一个很好的起点。如果你能更准确地了解非管理员用户,那就更好了
Given there is an admin user
And there is a customer
您应该实现这些步骤,比如
Given 'there is an admin' do
@admin = create_admin
end
Given 'there is a customer' do
@customer = create_customer
end
module UserCreationStepHelper
def create_admin
...
def create_customer
...
end
World UserCreationStepHelper
并将创建用户的方式推迟到助手方法
一旦你有了它,你就可以创造
假设有管理员和客户
并实施为
Given 'there is an admin and a customer' do
@admin, @customer = create_admin, create_customer
end
您的助手方法类似于
Given 'there is an admin' do
@admin = create_admin
end
Given 'there is a customer' do
@customer = create_customer
end
module UserCreationStepHelper
def create_admin
...
def create_customer
...
end
World UserCreationStepHelper
警告:以上是红宝石黄瓜,你需要翻译。你应该可以在cucumber.io上得到帮助