xUnit.BDD 4.0.0-beta.1

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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.1 is compatible.  netstandard1.2 was computed.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net45 was computed.  net451 was computed.  net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
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 14,056 10/10/2018
5.1.0 1,347 10/10/2018
5.0.1 3,903 4/26/2018
5.0.0 1,552 4/26/2018
5.0.0-slow-and-steady.1 631 4/26/2018
4.0.2 1,781 10/9/2017
4.0.2-reproducible-order.1 549 10/5/2017
4.0.1 1,473 10/2/2017
4.0.1-initialize-once.1 549 10/2/2017
4.0.0 1,472 10/2/2017
4.0.0-beta.3 552 9/28/2017
4.0.0-beta.2 536 9/27/2017
4.0.0-beta.1 632 9/27/2017
3.0.0 1,724 9/21/2017
2.2.0-beta2 1,645 4/22/2016
2.2.0-beta 1,417 2/18/2016
2.0.0 1,582 8/22/2017
1.9.2 3,873 2/20/2014
1.9.1.1 4,064 9/18/2012