BddPipe 2.2.0

A fluent API based on Gherkin syntax to assist with the Automated Testing aspect of Behaviour-Driven Development (BDD).

Install-Package BddPipe -Version 2.2.0
dotnet add package BddPipe --version 2.2.0
<PackageReference Include="BddPipe" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BddPipe --version 2.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

About BddPipe

This project was created to describe test steps. It has been developed to replace similar existing libraries as a more succinct and simpler to use alternative.

Goals

  • let each step define and return to the next step all the state it needs to proceed.
  • avoid declaring variables outside test step functions as a way to store/retreive data between steps
  • avoid having to set defaults for these declared variables before they are ready to be assigned
  • have better control of output if desired - the outcome is detailed and the default console output can be captured or replaced.

Getting started

Add the using statement:

using static BddPipe.Runner;

Basic example:

Given("two numbers", () => new { A = 5, B = 10 })
.When("the numbers are summed", args => new { Result = args.A + args.B })
.Then("sum should be as expected", arg =>
{
    arg.Result.Should().Be(15);
})
.Run();

Steps must end with a call to .Run() or the result is not evaluated.

Scenario:

It is optional to start with Scenario() for a scenario describing your method name, or Scenario(&quot;Your scenario title&quot;)

// This example will use the method name in the output
Scenario()
    .Given(...)

// This example will use "Your scenario title" in the output
Scenario("Your scenario title")
    .Given(...)

The scenario will then be at the top of the test output:

Scenario: Your scenario title  
  Given two numbers [Passed]  
  When the numbers are summed [Passed]  
  Then sum should be as expected [Passed]  

There are a number of overloads for the method steps: Given, When, Then, And, But.

When implementing steps, you can return from them whatever you like - including anonymous types or tuples.
If something is returned from one of these steps then all following steps using a parameter will have a parameter of this instance, until a different instance is returned from a step. This also allows Action steps to be placed between the step returning something and the step that will later make use of it.

Async:

Async steps can be provided via an async delegate implementation - you can provide a method returning Task or Task&lt;T&gt;:

    When("The numbers are summed", async args =>
    {
        await Task.Delay(10);
        return new { Result = args.A + args.B};
    })

Output:

By default the output is written to console. Each step will be marked as passed, failed, inconclusive or not run.
Steps after a failed or inconclusive step will not be run.

Given two numbers [Passed]  
When the numbers are summed [Passed]  
Then sum should be as expected [Passed]  

You can instead be given this output by supplying an action to the final Run() call.
This will no longer console write the output by default and will give the result to your implementation.

.Run(output =&gt; { /*handle output*/ });

It's still possible to call Runner.WriteLogsToConsole(...) from your implementation to use the default console logging.

You can also get the details of the output from the result of the final Run() call as an instance of BddPipeResult&lt;T&gt;.

Actions:

It's also possible to use only actions for all steps and never return from them, but state then has to be maintained outside of the pipeline. This project has been built to avoid the need for this approach but it is still possible.

    int a = 0, b = 0;
    int result = 0;

    Given("two numbers", () =>
    {
        a = 6;
        b = 20;
    })
    ...

About BddPipe

This project was created to describe test steps. It has been developed to replace similar existing libraries as a more succinct and simpler to use alternative.

Goals

  • let each step define and return to the next step all the state it needs to proceed.
  • avoid declaring variables outside test step functions as a way to store/retreive data between steps
  • avoid having to set defaults for these declared variables before they are ready to be assigned
  • have better control of output if desired - the outcome is detailed and the default console output can be captured or replaced.

Getting started

Add the using statement:

using static BddPipe.Runner;

Basic example:

Given("two numbers", () => new { A = 5, B = 10 })
.When("the numbers are summed", args => new { Result = args.A + args.B })
.Then("sum should be as expected", arg =>
{
    arg.Result.Should().Be(15);
})
.Run();

Steps must end with a call to .Run() or the result is not evaluated.

Scenario:

It is optional to start with Scenario() for a scenario describing your method name, or Scenario(&quot;Your scenario title&quot;)

// This example will use the method name in the output
Scenario()
    .Given(...)

// This example will use "Your scenario title" in the output
Scenario("Your scenario title")
    .Given(...)

The scenario will then be at the top of the test output:

Scenario: Your scenario title  
  Given two numbers [Passed]  
  When the numbers are summed [Passed]  
  Then sum should be as expected [Passed]  

There are a number of overloads for the method steps: Given, When, Then, And, But.

When implementing steps, you can return from them whatever you like - including anonymous types or tuples.
If something is returned from one of these steps then all following steps using a parameter will have a parameter of this instance, until a different instance is returned from a step. This also allows Action steps to be placed between the step returning something and the step that will later make use of it.

Async:

Async steps can be provided via an async delegate implementation - you can provide a method returning Task or Task&lt;T&gt;:

    When("The numbers are summed", async args =>
    {
        await Task.Delay(10);
        return new { Result = args.A + args.B};
    })

Output:

By default the output is written to console. Each step will be marked as passed, failed, inconclusive or not run.
Steps after a failed or inconclusive step will not be run.

Given two numbers [Passed]  
When the numbers are summed [Passed]  
Then sum should be as expected [Passed]  

You can instead be given this output by supplying an action to the final Run() call.
This will no longer console write the output by default and will give the result to your implementation.

.Run(output =&gt; { /*handle output*/ });

It's still possible to call Runner.WriteLogsToConsole(...) from your implementation to use the default console logging.

You can also get the details of the output from the result of the final Run() call as an instance of BddPipeResult&lt;T&gt;.

Actions:

It's also possible to use only actions for all steps and never return from them, but state then has to be maintained outside of the pipeline. This project has been built to avoid the need for this approach but it is still possible.

    int a = 0, b = 0;
    int result = 0;

    Given("two numbers", () =>
    {
        a = 6;
        b = 20;
    })
    ...

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.2.0 773 3/1/2020
2.1.1 69 2/23/2020
2.1.0 2,424 2/6/2020
2.0.0 749 1/27/2020
2.0.0-rc 49 1/22/2020
1.0.5 2,107 10/9/2019
1.0.3 847 9/25/2019
1.0.2 76 9/18/2019
1.0.1 83 9/17/2019
1.0.1-rc 73 9/10/2019