Agendac#
Benefit -app
Frameworks specflow supports ide
Specflow technical featuresui
tags can be at feature level or scenario level to indicate special attributes, using symbol @spa
Header - Provide the feature name (Pretty much like a user story caption)code
Scenrio 1 - Provide the scenarioci
comment can be added at anywhere start with # to add remarkrem
Step 1 - Logical step (Using Given, When, Then, And / But is key word that help improve the readibility)get
All are in business languageinput
2. Map the feature file to csharp class and method code
using attributes [given] to map the code back to steps
download specflow extension(generate mapping c# code, Tools->Extension and Updates->Search Specflow Visual Studio Extension), nuget packages(framework that glue the feature with IDE Xunit.Runner.VisualStudio ), nuget test frameworks(Specflow.Xunit nuget)
3. Use scenario outline to organize parameterized inputs and outputs
Scenario Outline: Add numbers
Given I have a new calculator start with <current>
When I have entered <add> into the calculator
Then the result should be <result> on the screen
Examples:
| current | add | result |
| 100 | 20 | 120 |
| 200 | 30 | 230 |
| 234 | 22 | 11 |
namespace POC_LAB_Spec {
[Binding]
public class SpecFlowFeature1Steps
{ Calculator _cal;
[Given(@"I have a new calculator start with (.*)")]
public void GivenIHaveANewCalculatorStartWithCurrent(int current)
{ _cal = new Calculator(); _cal.Current = current; }
[When(@"I have entered (.*) into the calculator")]
public void WhenIHaveEnteredAddIntoTheCalculator(int add) { _cal.Add(add); }
[Then(@"the result should be (.*) on the screen")]
public void ThenTheResultShouldBeResultOnTheScreen(int result) { Assert.True(result == _cal.Current); }
} }