Set fire 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
// 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 (Coming Soon), 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! | Coming Soon |
Logging | Core logging abstractions. Used to assert against logged messages, useful for cases like testing background services | Coming Soon |
AutoFixture | Integration with AutoFixture to simplify arrange steps | Coming Soon |
Bogus | Integration with Bogus to simplify arrange steps | Coming Soon |
Verify.Xunit | Integration with Verify.Xunit to simplify assert steps | Coming Soon |
Verify.Xunit | Integration with Verify.NUnit to simplify assert steps | Coming Soon |
Http | Extension methods for testing Http servers | Coming Soon |
FunctionApp | Extension methods for testing Function apps | Coming Soon |
Background | Extension methods for testing Background services | Coming Soon |
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.