我有几个 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 指令编写任何类型的方法并从每个后台代码调用此方法吗?
最佳答案
不要忘记您的 [Binding]
是全局的。理论上,您可以拥有一个包含所有 Given
\When
\Then
的绑定(bind)文件。
此外,为什么不向 WebService 发送一个重置命令,而是以这种方式构建它们?您可以启用一个新命令,例如 api/testing/deleteAll
,只有在您使用特殊配置值运行 webService 时才可用。
关于c# - 在 Specflow 中的两个特征文件之间重用背景定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19859606/