在 Specflow 中的两个特征文件之间重用背景定义 [英] Reuse background definition between two feature files in Specflow
问题描述
我有几个 specflow .feature 文件来测试 web api 项目的不同实体.
I have several specflow .feature files to test different entities of a web api project.
对于每个实体,我必须使用数据库中所有需要的数据创建一个背景,但在此之前我需要删除所有数据,并且需要使用 web api 调用(而不是通过 sql 查询)进行删除.我正在这样做:
For every entity I have to create a background with all the needed data in my database, but before of all I need to delete all data, and need to delete using web api calls (not by sql query). I'm doing this:
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 指令编写任何类型的方法,并从每个后台代码调用此方法吗?
It works perfect, but I have several .feature files that need to execute the same deleteAll methods. Can I write any kind of method with all the Given/When instructions in other .feature file (or another kind of file) and call this method from every background code?
推荐答案
不要忘记您的 [Binding]
是全局的.理论上,您可以拥有一个包含所有 Given
\ When
\ Then
的绑定文件.
Dont forget that your [Binding]
s are global. In theory you could have one binding file with all your Given
\ When
\ Then
s in it.
另外,为什么不向您的 WebService 发送一个重置命令,而不是以这种方式构建它们?您可以启用一个新命令,例如 api/testing/deleteAll
,该命令仅在您使用特殊配置值运行 webService 时才可用.
Also, why don't you send your WebService a single reset command, rather than building them up in this manner? You could enable a new command such as api/testing/deleteAll
which is only availble if you run your webService with a special config value.
这篇关于在 Specflow 中的两个特征文件之间重用背景定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!