Quick start - adamralph/xbehave.net GitHub Wiki

  • Ensure you are able to execute xUnit.net tests, in Visual Studio or your environment of choice
  • Create a new class library project and add a reference to xBehave.net
  • Add the following code to a class file in your project:
    namespace XBehaveQuickStart
    {
        using Xbehave;
    
        public class Calculator
        {
            public int Add(int x, int y) => 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(() => Xunit.Assert.Equal(3, answer));
            }
        }
    }
    
  • Execute the scenario in exactly the same way you would normally execute an xUnit.net Fact or Theory

Voilà! You've just written and run your first xBehave.net scenario. You will see that five successful tests will have run: one for each step in the scenario.

For more information, see Writing scenarios and Running scenarios.