xUnit.BDD
4.0.0-beta.1
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
<PackageReference Include="xUnit.BDD" Version="4.0.0-beta.1" />
paket add xUnit.BDD --version 4.0.0-beta.1
#r "nuget: xUnit.BDD, 4.0.0-beta.1"
// 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 Observation
s 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 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.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. |
-
.NETFramework 4.5.2
- xunit.assert (>= 2.2.0)
- xunit.extensibility.core (>= 2.2.0)
- xunit.extensibility.execution (>= 2.2.0)
-
.NETStandard 1.1
- NETStandard.Library (>= 1.6.1)
- xunit.assert (>= 2.2.0)
- xunit.extensibility.core (>= 2.2.0)
- xunit.extensibility.execution (>= 2.2.0)
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,790 | 10/10/2018 |
5.1.0 | 1,405 | 10/10/2018 |
5.0.1 | 4,048 | 4/26/2018 |
5.0.0 | 1,610 | 4/26/2018 |
5.0.0-slow-and-steady.1 | 661 | 4/26/2018 |
4.0.2 | 1,833 | 10/9/2017 |
4.0.2-reproducible-order.1 | 577 | 10/5/2017 |
4.0.1 | 1,526 | 10/2/2017 |
4.0.1-initialize-once.1 | 581 | 10/2/2017 |
4.0.0 | 1,525 | 10/2/2017 |
4.0.0-beta.3 | 582 | 9/28/2017 |
4.0.0-beta.2 | 564 | 9/27/2017 |
4.0.0-beta.1 | 666 | 9/27/2017 |
3.0.0 | 1,843 | 9/21/2017 |
2.2.0-beta2 | 1,713 | 4/22/2016 |
2.2.0-beta | 1,462 | 2/18/2016 |
2.0.0 | 1,629 | 8/22/2017 |
1.9.2 | 4,016 | 2/20/2014 |
1.9.1.1 | 4,486 | 9/18/2012 |