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

Quickstart

Adam Ralph edited this page Sep 29, 2013 · 19 revisions
  • Ensure you are able to execute xUnit.net tests in Visual Studio (see xUnit.net)
  • Create a new Class Library project in Visual Studio
  • Open the package manager console
    • Tools -> Library Package Manager -> Package Manager Console
  • Execute Install-Package Xbehave
  • Add the following code to a class file in your project:
namespace XBehaveQuickStart
{
    using Xbehave;
    using Xunit;

    public class Calculator
    {
        public int Add(int x, int y)
        {
            return x + y;
        }
    }

    public class CalculatorFeature
    {
        [Scenario]
        public void Addition(int x, int y, Calculator calculator, int answer)
        {
            "Given the number 1"
                .Given(() => x = 1);

            "And the number 2"
                .And(() => y = 2);

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

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

            "Then the answer is 3"
                .Then(() => Assert.Equal(3, answer));
        }
    }
}
  • Execute the scenario in exactly the same way you would normally execute an xUnit.net Fact or Theory
  • Observe the execution of 5 successful tests, one for each step in the scenario
  • Voilà - you've just written and successfully executed your first xBehave.net scenario

For more information, see Writing scenarios

Clone this wiki locally