🏃 Getting Started 📚 Documentation
Set 🔥 to your old unit tests! A better way to write tests 🧪 in C#.
- Test framework agnostic
- Zero dependencies
- Easy to use and extend
- More maintainable
- Integrations to your favourite test libraries
- Unit, Integration, Property any sort of test!
// Arrange act assert style
using static BunsenBurner.Aaa;
namespace SomeNamespace;
public static class Tests
{
[Fact(DisplayName = "Example AAA test!!!")]
public static async Task SomeTest() =>
await Arrange(() => new SUT(...))
.Act(async sut => await sut.SomeMethod(...))
.Assert(result => Assert.Equal("should be this", result));
}
// Given when then style
using static BunsenBurner.Bdd;
namespace SomeNamespace;
public static class Tests
{
[Fact(DisplayName = "Example BDD test!!!")]
public static async Task SomeTest() =>
await Given(() => new SUT(...))
.When(async sut => await sut.SomeMethod(...))
.Then(result => Assert.Equal("should be this", result));
}
To use this library, simply include BunsenBurner.dll
in your project or grab
it from NuGet, and add this to
the top of each test .cs
file
that needs it:
using static BunsenBurner.Aaa; // For Arrange act assert
or
using static BunsenBurner.Bdd; // For Given when then
Click through to the links bellow for further details.
Library | Description | Nu-Get |
---|---|---|
Core | Core test abstraction that makes it all possible. This is all that is required to get started! | |
Logging | Core logging abstractions. Used to assert against logged messages, useful for cases like testing background services | |
Xunit | Integration with xUnit.net to easily consume Bunsen Burner | |
NUnit | Integration with NUnit to easily consume Bunsen Burner | |
AutoFixture | Integration with AutoFixture to simplify arrange steps | |
Bogus | Integration with Bogus to simplify arrange steps | |
DependencyInjection | Provides tests for validating Dependency Injection containers | |
Hedgehog | Integration with Hedgehog to write property based tests | |
BenchmarkDotNet | Integration with BenchmarkDotNet to write performance tests | |
Verify.Xunit | Integration with Verify.Xunit to simplify assert steps | |
Verify.NUnit | Integration with Verify.NUnit to simplify assert steps | |
Http | Extension methods for testing Http servers | |
FunctionApp | Extension methods for testing Function apps | |
Background | Extension methods for testing Background services |
Most tests in the C# are written in an arrange, act, assert style, like so,
using Xunit;
namespace SomeNamespace;
public static class Tests
{
[Fact]
public static async Task SomeTest()
{
// Arrange
var sut = new SUT(...);
// Act
var result = await sut.SomeMethod(...);
// Assert
Assert.Equal("should be this", result);
}
}
This library aims to formalize this structure in the following ways,
- Enforces that all tests must be arranged before acting and acted upon before assertions can occur
- Converts tests to data, which can be composed and built up then executed
- Works well wth theories
- Because tests are just data, functions can be used to extend them and compose
them together
- Works will with extension methods and other test libraries, use cases
// can use implicit usings
using Xunit;
using static BunsenBurner.Aaa;
namespace SomeNamespace;
public static class Tests
{
[Fact(DisplayName = "Example AAA test!!!")]
public static async Task SomeTest() =>
// arrange starts a new test,
// whatever type it returns can be used when acting
await Arrange(() => new SUT(...))
// act on the arranged data, async is supported in all test steps
.Act(async sut => await sut.SomeMethod(...))
// assert against the result of acting
.Assert(result => Assert.Equal("should be this", result));
}
For more details/information have a look the test projects or create an issue.