johnfelipe / Bunsen-Burner

Set :fire: to your old unit tests! A better way to write tests in C# :test_tube:

Home Page:https://bmazzarol.github.io/Bunsen-Burner/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bunsen Burner

Bunsen Burner

🏃 Getting Started 📚 Documentation

Nuget Coverage Quality Gate Status CD Build Check Markdown CodeQL

Set 🔥 to your old unit tests! A better way to write tests 🧪 in C#.

Features

  • 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));
}

Getting Started

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! Nuget
Logging Core logging abstractions. Used to assert against logged messages, useful for cases like testing background services Nuget
Xunit Integration with xUnit.net to easily consume Bunsen Burner Nuget
NUnit Integration with NUnit to easily consume Bunsen Burner Nuget
AutoFixture Integration with AutoFixture to simplify arrange steps Nuget
Bogus Integration with Bogus to simplify arrange steps Nuget
DependencyInjection Provides tests for validating Dependency Injection containers Nuget
Hedgehog Integration with Hedgehog to write property based tests Nuget
BenchmarkDotNet Integration with BenchmarkDotNet to write performance tests Nuget
Verify.Xunit Integration with Verify.Xunit to simplify assert steps Nuget
Verify.NUnit Integration with Verify.NUnit to simplify assert steps Nuget
Http Extension methods for testing Http servers Nuget
FunctionApp Extension methods for testing Function apps Nuget
Background Extension methods for testing Background services Nuget

Why?

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.

Attributions

Fire icons created by juicy_fish

About

Set :fire: to your old unit tests! A better way to write tests in C# :test_tube:

https://bmazzarol.github.io/Bunsen-Burner/

License:MIT License


Languages

Language:C# 99.5%Language:Shell 0.2%Language:JavaScript 0.2%Language:CSS 0.1%