我是否可以将一个功能文件调用到同一套件中存在的另一个功能文件中(调用方案的解决方案也可以)

时间:2015-11-26 20:11:10

标签: c# automation bdd specflow gherkin

我有一个测试套件,我在不同的功能文件中有多个BDD场景,如下所述,

**FeatureFile1**

Scenario: User is performing 123 funtionality

Given A,B,E,F,G
When User does A
Then Output is Aresult
When User does B
Then Output is Bresult
When User does E
Then Output is Eresult
When USer does F
Then Output is Fresult
When User does G
Then Output is Gresult


**FeatureFile2**

Senario: User is performing 4567 functionality

Given M,N,A,B,E,F,G,P,Q
When User does M
Then Output is Mresult
When User does N
Then Output is Nresult
When User does A
Then Output is Aresult
When User does B
Then Output is Bresult
When User does E
Then Output is Eresult
When USer does F
Then Output is Fresult
When User does G
Then Output is Gresult
When User does P
Then Output is Presult
When User does Q
Then Output is Qresult



**FeatureFile3**

Senario: User is performing 890 functionality
Given U,V,A,B,E,F,G,X,Y,Z
When User does U
Then Output is Uresult
When User does V
Then Output is Vresult
When User does A
Then Output is Aresult
and User does B
Then Output is Bresult
When User does E
Then Output is Eresult
When USer does F
Then Output is Fresult
When User does G
Then Output is Gresult
When User does X
Then Output is Xresult
When User does Y
Then Output is Yresult
When User does Z
Then Output is Zresult

如果你仔细看我的第一个特征文件在我的第二和第三个文件中完全重复(在两个步骤之间)。

有什么方法可以使用单行在其他文件中调用我的第一个特征文件(FeatureFile2理解它必须调用FeatureFile1,同样适用于其他情况)

这些将减少复制+粘贴对我来说,而我的其他场景(冗长的一个)将看起来紧凑和可呈现。因为我是BDD和C#的新手,希望得到帮助。我试着寻求解决方案,但却找不到具体的东西。

如果我可以在FeatureFile2中调用FeatureFile1中存在的场景......那也可以。

应该写什么代码????

使用Specflow ||的框架 编码C#||的语言 BDD语言小黄瓜

2 个答案:

答案 0 :(得分:1)

我通常解决这种情况的方法是创建一个步骤,它包含其他几个步骤,然后在第二个和第三个功能中调用它。您可以在this answer

中查看此方法的示例

答案 1 :(得分:0)

我们使用vstest控制台。 例如, 当场景没有准备数据时, 在第一步中,我们运行数据准备的特殊功能 How do I launch application one from another in C#?

关于控制台运行的参数是这个 How do you run SpecFlow scenarios from the command line using MSTest?