DrillSergeant 0.0.12-alpha

This is a prerelease version of DrillSergeant.
There is a newer version of this package available.
See the version list below for details.
dotnet add package DrillSergeant --version 0.0.12-alpha
NuGet\Install-Package DrillSergeant -Version 0.0.12-alpha
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DrillSergeant" Version="0.0.12-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DrillSergeant --version 0.0.12-alpha
#r "nuget: DrillSergeant, 0.0.12-alpha"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DrillSergeant as a Cake Addin
#addin nuget:?package=DrillSergeant&version=0.0.12-alpha&prerelease

// Install DrillSergeant as a Cake Tool
#tool nuget:?package=DrillSergeant&version=0.0.12-alpha&prerelease

DrillSergeant

.net behavior driven testing written by developers, for developers.

Summary

DrillSergeant is a behavior testing library that empowers developers to apply BDD practices with minimal amount of friction. Simply import the package and write your behaviors in familiar C# syntax.

Getting Started

For a complete example of a feature, see the following example.

A Basic Calculator Service

Lets say we have a Calculator service. For this example we'll define it as a simple class.

public class Calculator
{
    public int Add(int a, int b) => a + b;
    public int Sub(int a, int b) => a - b;
}

We can write a behavior test like so:

public class CalculatorTests
{
    private readonly Calculator _calculator = new();

    [Behavior]
    [InlineData(1,2,3)]
    [InlineData(2,3,5)]
    public int TestAdditionBehavior(int a, int b, int expected)
    {
        var input = new
        {
            A = a,
            B = b,
            Expected = expected
        };

        return new Behavior(input)
            .Given(SetFirstNumber)
            .Given(SetSecondNumber)
            .When(AddNumbers)
            .Then(CheckResult);
    }

    [Behavior]
    [InlineData(3,2,1)]
    [InlineData(5,2,3)]
    public int TestSubtractionBehavior(int a, int b, int expected)
    {
        var input = new
        {
            A = a,
            B = b,
            Expected = expected
        };

        return new Behavior(input)
            .Given(SetFirstNumber)
            .Given(SetSecondNumber)
            .When(SubtractNumbers)
            .Then(CheckResult);
    }

    // Given Steps.
    private void SetFirstNumber(dynamic context, dynamic input) => context.A = input.A;
    private void SetSecondNumber(dynamic context, dynamic input) => context.B = input.B;

    // When Steps.
    private void AddNumbers(dynamic context) => context.Result = _calculator.Add(context.A, context.B);
    private void SubtractNumbers(dynamic context) => context.Result = _calculator.Sub(context.A, context.B);

    // Then Steps.
    private void CheckResult(dynamic context, dynamic input) => Assert.Equal(input.Expected, context.Result);
}

Behaviors are written in same fashion as a normal xunit [Theory]. The only difference is that it is marked using the [Behavior] attribute and must return an instance of type IBehavior.

Why Write Tests This Way?

Unlike in normal unit tests, behavior tests are composed of a series of pluggable steps that can be re-used to test multiple behaviors. See the Cucumber documentation for an introduction into behavior testing.

More Information

For more information, please see the wikis.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on DrillSergeant:

Package Downloads
DrillSergeant.MSTest

Write behavior tests in pure C#.

DrillSergeant.NUnit3

Write behavior tests in pure C#.

DrillSergeant.Xunit2

Write behavior tests in pure C#.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.2 38 4/21/2024
1.2.1 31 4/21/2024
1.2.0 54 2/20/2024
1.2.0-alpha.40 70 1/20/2024
1.2.0-alpha.39 46 1/20/2024
1.2.0-alpha.38 47 1/20/2024
1.2.0-alpha.37 44 1/20/2024
1.2.0-alpha.35 127 11/19/2023
1.2.0-alpha.34 53 11/19/2023
1.2.0-alpha.33 57 11/13/2023
1.1.8 40 2/20/2024
1.1.2 71 1/20/2024
1.1.1 216 11/12/2023
1.1.0-alpha.42 55 11/12/2023
1.1.0-alpha.41 53 11/12/2023
1.1.0-alpha.39 49 11/12/2023
1.1.0-alpha.38 55 11/12/2023
1.1.0-alpha.37 56 11/12/2023
1.1.0-alpha.35 55 11/12/2023
1.0.3 159 10/21/2023
1.0.1 141 10/12/2023
1.0.0-beta.53 67 9/30/2023
1.0.0-beta.52 58 9/29/2023
0.6.2 156 8/20/2023
0.6.1-beta 110 8/20/2023
0.6.0-beta 111 8/20/2023
0.5.0 166 7/20/2023
0.4.0 166 7/16/2023
0.3.0-beta 140 7/12/2023
0.2.0-beta 140 7/9/2023
0.1.0-beta 77 7/4/2023
0.0.17-alpha 96 7/3/2023
0.0.16-alpha 92 6/30/2023
0.0.15-alpha 105 6/29/2023
0.0.14-alpha 97 6/23/2023
0.0.13-alpha 90 6/23/2023
0.0.12-alpha 91 6/16/2023
0.0.11-alpha 93 6/14/2023
0.0.10-alpha 93 6/10/2023
0.0.9-alpha 90 5/28/2023
0.0.8-alpha 90 5/25/2023
0.0.7-alpha 86 5/23/2023
0.0.6-alpha 89 5/20/2023
0.0.5-alpha 97 5/20/2023
0.0.4-alpha 91 5/17/2023
0.0.3-alpha 83 5/14/2023
0.0.2-alpha 89 5/12/2023