Skip to content

BonnyAD9/Bny.UnitTests

Repository files navigation

Bny.UnitTests

Bny.UnitTests is a library that makes unit testing in C# simpler.

In this repository

  • Bny.UnitTests - the library
  • Bny.UnitTests.Tests - unit tests
  • Bny.UnitTests.Examples - example usage
  • Documentation - Doxygen generated documentation

How to use

  • for detailed examples see Bny.UnitTests.Examples

Prepare your test classes

[UnitTest] // mark test classes with the [UnitTest] attribute
class TestSomething
{
    [UnitTest] // mark test functions with the [UnitTest] attribute
    static void Test_SomePart(Asserter a)
    { // all the test functions must have signature same as Action<Asserter>
        a.Assert(/* your assertion */);
        a.Assert(/* your next assertion */);
        // ...
    }
    
    [UnitTest]
    static void Test_OtherPart(Asserter a)
    {
        a.Assert(SomeHelperFunction(/* parameters */));
        // ...
    }
    
    static bool SomeHelperFunction(/* parameters */) { /* ... */ }
}

[UnitTest]
class TestSomethingElse { /* ... */ }

Run all the tests

Use the Tester.TestAll method to run all the tests in all the classes with the [UnitTest] attribute

Tester.TestAll();

Tester.TestAll parameters

  • logAmount: changes the amount of information written to the output
    • default value is LogAmount.Default
  • @out: the output writer
    • default value is null which means Console.Out (standard output stream)
  • formatted: determines whether the output is formatted with ANSI escape codes (colors)
    • default value is true

Example output

(Default parameters) image

How to get it

This library is available as a NuGet Package

Links