2

我有几个 specflow .feature 文件来测试 web api 项目的不同实体。

对于每个实体,我必须在我的数据库中创建一个包含所有需要数据的背景,但首先我需要删除所有数据,并且需要使用 web api 调用(而不是通过 sql 查询)删除。我正在这样做:

Background: 
Given I make a new request to localhost on port 53364 
    And the path is api/voipport/deleteAll 
    And the request type is Delete
    When the request has completed
Given I make a new request to localhost on port 53364 
    And the path is api/loopblockingexception/deleteAll 
    And the request type is Delete
    When the request has completed
Given I make a new request to localhost on port 53364 
    And the path is api/stimulationcode/deleteAll 
    And the request type is Delete
    When the request has completed
Given I make a new request to localhost on port 53364 
    And the path is api/switch/deleteAllMtp3
    And the request type is Delete
    When the request has completed
Given I make a new request to localhost on port 53364 
    And the path is api/enviroment/deleteAll 
    And the request type is Delete
    When the request has completed

Given it has the following topologies
    | Id | Name  | Description  |
    | 1  | Test  | Description  |
    | 2  | Test2 | Descritpion2 |
Given it has the following eas
    | Id | TopologyId | Name  | Description  | SipListenIPAddress | SipListenPort | SipTelephonyCapacity |
    | 1  | 1          | Test  | Description1 | 127.0.0.1          | 8080          | 5                    |
Given it has the following networks
    | Id | TopologyId | NetworkTypeId | Name  | CliPrivacyRespected |
    | 1  | 1          | 2             | Test1 | Description1        |
    | 2  | 1          | 1             | Test2 | Description2        |
Given it has the following switchs
    | Id | NetworkId | SwitchType | Name          | Description              |
    | 1  | 1         | 2          | Ss7SwitchTest | Ss7SwitchTestDescription |
    | 2  | 1         | 1          | SipSwitchTest | SipSwitchTestDescription |
Given it has the following mtp3Switchs
    | Id | Name            | Description                | SignallingHost | SignallingLinkCode | SwitchId | EasId |
    | 1  | SwitchMtp3Test  | SwitchMtp3DescriptionTest  | 192.168.1.1    | 13245              | 1        | 1     |
    | 2  | SwitchMtp3Test2 | SwitchMtp3DescriptionTest2 | 192.168.1.2    | 13246              | 1        | 1     |

它运行完美,但我有几个 .feature 文件需要执行相同的 deleteAll 方法。我可以使用其他 .feature 文件(或其他类型的文件)中的所有 Given/When 指令编写任何类型的方法,并从每个后台代码中调用此方法吗?

4

1 回答 1

1

不要忘记您[Binding]的 s 是全球性的。理论上,您可以拥有一个包含所有Given\的绑定文件WhenThen

另外,您为什么不向您的 WebService 发送一个重置命令,而不是以这种方式构建它们呢?您可以启用一个新命令,例如api/testing/deleteAll只有在您使用特殊配置值运行 webService 时才可用。

于 2013-11-08T13:34:20.980 回答