至此,我们已经可以使用Specflow写一个完整的Feature文件,并添加多个Scenario以及编写Step和StepDefinition来运行testcase了。文本的Feature文件最终是如何变成testcase呢?
当你添加了一个Scenario的时候,Specflow会将你的Feature文件解析并生成一个测试类,其名称与该Feature名称相同。
例如,添加的Scenario为
Feature: ArithmeticFeature
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
@mytag
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
对应的测试类(testcase class)
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.3.2.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
public partial class ArithmeticFeatureFeature
{
private static TechTalk.SpecFlow.ITestRunner testRunner;
private Microsoft.VisualStudio.TestTools.UnitTesting.TestContext _testContext;
public virtual Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext
{
get
{
return this._testContext;
}
set
{
this._testContext = value;
}
}
[Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute()]
public static void FeatureSetup(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext)
{
testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(null, 0);
TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "ArithmeticFeature", "\tIn order to avoid silly mistakes\r\n\tAs a math idiot\r\n\tI want to be told the sum o" +
"f two