在使用SpecFlow框架进行封装方面,我有以下问题,目标是在方法2中封装方法1,以下是以下功能/场景以及生成的步骤,我相信我需要使用string.format 。无论如何,请建议如何封装方法1至方法2中给出的现有内容。
首先请查看场景。
Scenario Outline: Compare XYZ data against the given templates
Given I have located the XYZ file from <xyzfilelocation>
Examples:
| xyzfilelocation |
| Tests\Meebu\Doggg\Cat\xyz\Yhyh800\Yhyh800_TheId_1234567.FirstOne.xml |
| Tests\Meebu\Doggg\Cat\xyz\Yhyh800\Yhyh800_TheId_7654321.SecondTwo.xml|
第二步查看生成的步骤。
//Method 1
[Given(@"I have located the XYZ file from (.*)")]
public void GivenIHaveLocatedTheXYZFileFromLocation(string xyzfilelocation)
{
string file = new System.IO.DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.FullName + "\\" + xyzfilelocation;
_context.ActualXYZ = new XmlDocument();
_context.ActualXYZ.Load(file);
}
//方法2,我想在这里封装上述方法, 我正在尝试以下操作,这是正确的方法吗,我相信我需要做string.format,请告知/此功能是否有效,是否封装?
[When(@"I compare XYZ file (.*)")]
public void WhenICompareXYZFile(string xyzfilelocation)
{
//Calling the method Given I have located the XYZ file from <xyzfilelocation>
Given(string.Format("I have located the XYZ file from {0}", xyzfilelocation));
}
答案 0 :(得分:0)
您可以像在标准类中那样调用方法:
GivenIHaveLocatedTheXYZFileFromLocation(string.Format("I have located the XYZ file from {0}", xyzfilelocation));