Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Scenarios with examples

Adam Ralph edited this page Sep 29, 2013 · 18 revisions

xBehave.net allows the passing of example values for the parameters in a scenario method.

This is equivalent to Cucumber's Scenario Outlines feature and is very similar to xUnit.net's [Theory] attribute for data driven testing.

E.g.

[Scenario]
[Example(1, 2, 3)]
[Example(2, 3, 5)]
public void Addition(int x, int y, int expectedAnswer, Calculator calculator, int answer)
{
    "Given the number {0}"
        .Given(() => { });

    "And the number {1}"
        .And(() => { });

    "And a calculator"
        .And(() => calculator = new Calculator());

    "When I add the numbers together"
        .When(() => answer = calculator.Add(x, y));

    "Then the answer is {2}"
        .Then(() => Assert.Equal(expectedAnswer, answer));
}

results in this output: xbehave.xunit.console.html.examples.png

Clone this wiki locally