xUnit.BDD 4.0.0-beta.1

.NET Standard 1.1 .NET Framework 4.5.2
This is a prerelease version of xUnit.BDD.
There is a newer version of this package available.
See the version list below for details.
dotnet add package xUnit.BDD --version 4.0.0-beta.1
NuGet\Install-Package xUnit.BDD -Version 4.0.0-beta.1
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="xUnit.BDD" Version="4.0.0-beta.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add xUnit.BDD --version 4.0.0-beta.1
#r "nuget: xUnit.BDD, 4.0.0-beta.1"
#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 xUnit.BDD as a Cake Addin
#addin nuget:?package=xUnit.BDD&version=4.0.0-beta.1&prerelease

// Install xUnit.BDD as a Cake Tool
#tool nuget:?package=xUnit.BDD&version=4.0.0-beta.1&prerelease

xUnit.Net BDD Extensions

Extends xUnit.Net with Behavior Driven Development style fixtures.

Some of the design goals include:

  • Use natural C# constructs to control things such as BDD contexts and concerns. For example, the context of the specification is defined in the class constructor and the concern for the fixture is defined by its namespace.
  • Async tests are a first class citizen.

See here for a full introduction

How to Use

Install via nuget

dotnet add package xUnit.BDD

Write a Scenario

using Xunit;

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

public class when_adding_two_numbers : Specification
{
	readonly Calculator calc;
	int result;

	public when_adding_two_numbers()
	{
		calc = new Calculator();
	}

	protected override Task ObserveAsync()
	{
		result = calc.Add(1, 2);
		return Task.CompletedTask;
	}

	[Observation]
	public void should_return_correct_result()
	{
		result.ShouldEqual(3);
	}
}

This is a contrived example, but the idea is to run the code you're observing in the ObserveAsync method and have one or more Observations on what you observed. This way, when a test (Observation) fails, the language of the class and method (the scenario) should be granular enough to let you know exactly what failed.

Async Scenarios

The Specification is async by default (e.g. the ObserveAsync method is expected to run async) since this is a brave new async world we live in. Since C# does not allow async constructors or async Dispose methods, if you need to do any async setup or teardown for the test, you should override InitializeAsync and/or DisposeAsync.

public class when_doing_some_async_thing : Specification
{
	string result;

	protected override async Task InitializeAsync()
	{
		await myThing.DoAThingAsync();
	}

	protected override async Task ObserveAsync()
	{
		result = await myThing.DoTheThing();
	}

	[Observation]
	public async Task should_return_correct_result()
	{
		string otherThing = await someOtherThing.DoAnotherThing();
		result.ShouldEqual(otherThing);
	}
}

You should explicitly avoid implementing Xunit's IAsyncLifetime since that is what Specification does internally to do its magic. Use the hooks on the Specification class.

Building Locally

After cloning, run:

dotnet restore
dotnet build

To run the test cases:

cd test
dotnet test
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 netstandard2.1
.NET Framework net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen30 tizen40 tizen60
Universal Windows Platform uap uap10.0
Windows Phone wpa81
Windows Store netcore netcore45 netcore451
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.0 11,472 10/10/2018
5.1.0 698 10/10/2018
5.0.1 3,199 4/26/2018
5.0.0 892 4/26/2018
5.0.0-slow-and-steady.1 574 4/26/2018
4.0.2 1,133 10/9/2017
4.0.2-reproducible-order.1 505 10/5/2017
4.0.1 808 10/2/2017
4.0.1-initialize-once.1 497 10/2/2017
4.0.0 800 10/2/2017
4.0.0-beta.3 502 9/28/2017
4.0.0-beta.2 490 9/27/2017
4.0.0-beta.1 572 9/27/2017
3.0.0 1,002 9/21/2017
2.2.0-beta2 1,038 4/22/2016
2.2.0-beta 803 2/18/2016
2.0.0 931 8/22/2017
1.9.2 3,054 2/20/2014
1.9.1.1 2,906 9/18/2012