-
Notifications
You must be signed in to change notification settings - Fork 20
Scenario outline
MorganPersson edited this page Nov 26, 2012
·
2 revisions
Instead of repeating the same example and only change the values you can use examples.
You write an example like this:
Feature: add, subtract, divide and multiply
Scenario: Add numbers
Given I have entered [num1] into the calculator
And I have entered [num2] into the calculator
When I add the numbers
Then the sum should be [result]
Examples:
|num1|num2|result|
| 1| 2| 3|
| -1| 2| 1|
| 1| -2| -1|
| -2| -3| -5|
As you may have noted, the feature has ``Scenario: Add Numbers. You may also use
Scenario Outline: Add numbers`, for nbehave it doesnt matter which one you use.
Code for the steps is implemented
using NBehave.Narrator.Framework;
using NBehave.Spec.NUnit;
namespace NBehave.Examples.Calculator_table.Steps
{
[ActionSteps]
public class AddNumbers
{
private Calculator _calculator;
[BeforeScenario]
public void SetUp_scenario()
{
_calculator = new Calculator();
}
[Given(@"I have entered $number into the calculator")]
public void Enter_number(int number)
{
_calculator.Enter(number);
}
[When(@"I add the numbers")]
public void Add()
{
_calculator.Add();
}
[Then(@"the sum should be $result")]
public void Result(int result)
{
_calculator.Value().ShouldEqual(result);
}
}
}