Quickstart

Adam Ralph edited this page Aug 6, 2015 · 13 revisions
  • Ensure you are able to execute xUnit.net tests in Visual Studio
  • Create a new Class Library project
  • 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"
                .x(() => x = 1);

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

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

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

            "Then the answer is 3"
                .x(() => 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 and Running scenarios.