Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Test Framework

The test framework abstracts the boilerplate required to use an auto mocking container in a unit test project. This means your test classes can focus on the job at hand, whilst all the setup and management of the auto mocking container is handled elsewhere.

Why?

Without the test framework or auto mocking, unit tests can easily become brittle and tiresome to maintain. In this example every time a dependency is added to the service, we have to refactor it into all our existing tests before we can start writing new code.

[Test]
public void DoWork_brittle_test()
{
    // Arrange
    var fooService = Substitute.For<IFooService>();
    var service = new Service(fooService);
            
    var input = "foo";
    var expected = "bar";

    // Act
    var actual = service.DoWork(input);

    // Assert
    actual.Should().Be(expected);
}

In this version we use the test framework to instantiate the class we are testing. The Subject property gets the class we are testing from the auto mocking container, thus isolating our test class from it.

[Test]
public void DoWork_robust_test()
{
    // Arrange
    var input = "foo";
    var expected = "bar";

    // Act
    var actual = Subject.DoWork(input);

    // Assert
    actual.Should().Be(expected);
}

Installing

Please install the appropiate package from NuGet:

PM> Install-Package TestFramework.NUnit.Ninject.Moq

or

PM> Install-Package TestFramework.NUnit.Ninject.NSubstitute

Documentation

Please see the wiki.

Credits

The initial version of the framework was witten for thebigword. Thank you to them and @a-h for agreeing to open source it.

Continuous Integration

Build status

About

Test framework abstracts the boilerplate required to use an auto mocking container in a unit test project.

Resources

License

Packages

No packages published