NuBehave 0.9.3
dotnet add package NuBehave --version 0.9.3
NuGet\Install-Package NuBehave -Version 0.9.3
<PackageReference Include="NuBehave" Version="0.9.3" />
<PackageVersion Include="NuBehave" Version="0.9.3" />
<PackageReference Include="NuBehave" />
paket add NuBehave --version 0.9.3
#r "nuget: NuBehave, 0.9.3"
#:package NuBehave@0.9.3
#addin nuget:?package=NuBehave&version=0.9.3
#tool nuget:?package=NuBehave&version=0.9.3
UBehave
A micro-library for writing BDD-style tests in C#. Inspired by xBehave.net.
Nuget packages:
The goal it to write behavior tests first, and then implement the code to make the tests pass. Which is mainly useful for integration testing, but you're free to use in anywhere.
Quickstart
In your xUnit or NUnit-Project, add a reference to UBehave or NuBehave and write your first test:
public class Calculator
{
public int Add(int x, int y) => x + y;
}
public class CalculatorFeature
{
[Scenario("A user wants to calculate an addition")]
public async Task Addition()
{
// Given
var calculator = new Calculator();
var x = 1;
var y = 2;
// When
await $"When I add the numbers {x} + {y} together"
.x(() => calculator.Add(x, y))
.Out(out var result);
// Then
await "Then the answer is 3"
.x(() => Assert.Equal(3, result.x));
}
}
Output:
STEP START: 'When I add the numbers 1 + 2 together'
STEP END: 'When I add the numbers 1 + 2 together' took 00:00:00.0001873
-----------------------------------------------------------------------
STEP START: 'Then the answer is 3'
STEP END: 'Then the answer is 3' took 00:00:00.0058363
------------------------------------------------------
Step by step
In BDD-Style, you write your tests first from a user perspective, and then implement the code step by step to make the tests pass. So you start with simple describing test method:
[Scenario("A user wants to request the weather")]
public async Task Addition()
{
// Given
await "Given a running ASP IntegrationTesting Server"
.Todo();
// When
await "When I ask the weather for tomorrow"
.Todo();
// Then
await "Then the answer is sunny, 20°C"
.Todo();
}
}
From here on you can implement the code step by step, and make the tests pass.
Even though not neccessary, UBehave ❤️ to be combinated with ASP System under test and Test Containers 🎉<br> And it doesn't matter if you call it 'You Behave' or 'Micro-Behave/µBehave'. It's a bit of both.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- JetBrains.Annotations (>= 2026.2.0)
- NUnit (>= 4.6.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.