繁体   English   中英

如何更有效地重用 Given Specflow 步骤

[英]How can I reuse the Given Specflow step more efficiently

我的想法不多了......我有这个场景大纲:

Scenario Outline: Member is assigned to dynamic scope

    Given a dynamic device scope with "<id>", "<name>", "<description>" and "<filter>" exist

    When I post new member assign request with "<member id>", "<first name>", "<last name>" and "<email>"

    Then the response is "<status code>"

    And a member with "<member id>", "<first name>", "<last name>" and "<email>" is added to the dynamic device scope
    Examples:
| no | id | name | desc | filter | member id | first name | last name | email| status code |

| 1  | 01 | name | desc | filter | ee749612  | first      | last    | t1@mail.com| Created |

我希望能够重用此场景大纲并为动态人员 scope 运行它。 像这样的东西:

Given a **dynamic people** scope with "<id>", "<name>", "<description>" and "<filter>" exist

动态设备的 Given 背后的步骤如下所示:

[Given(@"a dynamic device scope with ""(.*)"", ""(.*)"", ""(.*)"" and ""(.*)"" exist")]
public void GivenADynamicDeviceScopeWithAndExist(Guid id, string name, string description, string filter)

    {
        _scopeId = _scenarioSettings.ScopesStorage.BuildTestDynamicDeviceScope(id, name, description, filter);
    }

你知道如何在复制整个场景的情况下改进这个吗?

由于步骤定义正在调用BuildTestDynamicDeviceScope ,因此似乎 C# API 特定于所请求的 scope 类型。 我建议创建两个单独的步骤:

Given a dynamic device scope...
Given a dynamic people scope...

由于场景大纲基本上是经过预处理的,因此请尝试将步骤中的devicepeople设置为场景大纲中的变量:

Scenario Outline: Member is assigned to dynamic scope
    Given a dynamic <scope type> scope with "<id>", "<name>", "<description>" and "<filter>" exist
    When I post new member assign request with "<member id>", "<first name>", "<last name>" and "<email>"
    Then the response is "<status code>"
    And a member with "<member id>", "<first name>", "<last name>" and "<email>" is added to the dynamic device scope

Examples:
    | scope type | no | id | name | desc | filter | member id | first name | last name | email      | status code |
    | device     | 1  | 01 | name | desc | filter | ee749612  | first      | last      | t1@mail.com| Created     |
    | people     | .. | .. | ...  | ...  | ...    | ...       | ...        | ...       | ...        | ...         |

重要的部分是:

Given a dynamic <scope type> scope with ...
                ^^^^^^^^^^^^

场景大纲令牌不需要替换步骤 arguments。 他们可以简单地替换步骤文本本身的一部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM