Last active
February 23, 2016 07:11
-
-
Save gasparnagy/54b3fe009bcb4a63f68c to your computer and use it in GitHub Desktop.
Examples for blog post "Running SpecFlow scenarios parallel with xUnit 2"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Addition | |
Scenario Outline: Add two numbers | |
Given I have entered <a> into the calculator | |
And I have entered <b> into the calculator | |
When I press add | |
Then the result should be <result> on the screen | |
Examples: | |
| case | a | b | result | | |
| classic | 50 | 70 | 120 | | |
| commutativity | 70 | 50 | 120 | | |
| zero | 0 | 42 | 42 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<specFlow> | |
<unitTestProvider name="xUnit" /> | |
</specFlow> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Calculator | |
{ | |
private readonly Stack<int> operands = new Stack<int>(); | |
public int Result | |
{ | |
get { return operands.Peek(); } | |
} | |
public void Enter(int operand) | |
{ | |
operands.Push(operand); | |
} | |
public void Add() | |
{ | |
operands.Push(operands.Pop() + operands.Pop()); | |
} | |
public void Multiply() | |
{ | |
operands.Push(operands.Pop() * operands.Pop()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Binding] | |
public class CalculatorSteps | |
{ | |
private readonly Calculator calculator = new Calculator(); | |
[Given(@"I have entered (.*) into the calculator")] | |
public void GivenIHaveEnteredIntoTheCalculator(int operand) | |
{ | |
calculator.Enter(operand); | |
} | |
[When(@"I press add")] | |
public void WhenIPressAdd() | |
{ | |
calculator.Add(); | |
} | |
//... | |
[Then(@"the result should be (.*) on the screen")] | |
public void ThenTheResultShouldBeOnTheScreen(int expectedResult) | |
{ | |
Assert.Equal(expectedResult, calculator.Result); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Multiplication | |
Scenario Outline: Add two numbers | |
Given I have entered <a> into the calculator | |
And I have entered <b> into the calculator | |
When I press multiply | |
Then the result should be <result> on the screen | |
Examples: | |
| case | a | b | result | | |
| classic | 50 | 70 | 3500 | | |
| commutativity | 70 | 50 | 3500 | | |
| zero | 0 | 42 | 0 | | |
| one | 1 | 42 | 42 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Given(@"I have entered (.*) into the calculator")] | |
public void GivenIHaveEnteredIntoTheCalculator(int operand) | |
{ | |
((Calculator)ScenarioContext.Current["calc"]).Enter(operand); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Binding] | |
public class CalculatorSteps | |
{ | |
private readonly ScenarioContext scenarioContext; | |
public CalculatorSteps(ScenarioContext scenarioContext) | |
{ | |
this.scenarioContext = scenarioContext; | |
} | |
[Given(@"I have entered (.*) into the calculator")] | |
public void GivenIHaveEnteredIntoTheCalculator(int operand) | |
{ | |
((Calculator)scenarioContext["calc"]).Enter(operand); | |
} | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment