Unit Testing Resources

Learn about the most common unit testing frameworks and related tools and where to find the most useful unit testing resources.


The purpose of this section is to describe the .NET unit testing landscape and its resources. Fortunately, there is an abundance of testing frameworks and related tools from which to choose.

.NET unit testing frameworks

The design of the testing frameworks below is all based on xUnit and therefore the syntax and design of all three frameworks are similar. If you complete all the lessons in this course, switching from NUnit to any of the other two popular frameworks will be easy. The following are the most common unit testing frameworks in the .NET environment:

Unit testing framework Description
NUnit NUnit is a unit testing framework for all .NET languages. Initially ported from JUnit, the current production release, version 3, has been completely rewritten with many new features and support for a wide range of .NET platforms.
xUnit.net xUnit.net is a free, open-source, community-focused unit testing tool for the .NET Framework. Written by the original inventor of NUnit v2, xUnit is the latest technology for unit testing C#, F#, VB.NET, and other .NET languages.
MSTest MSTest is an open-source test framework that is shipped along with the Visual Studio IDE.

.NET code coverage tools

There are various code coverage tools available. Unfortunately, the options for open-source code coverage tools are severely limited with the only open-source solution being AltCover. Although only AltCover was covered in this course, the principles of code coverage also apply to the other tools.

Code coverage tool Description
dotCover JetBrains’ dotCover is a .NET unit test runner and code coverage tool that integrates with Visual Studio and JetBrains Rider.
NCover NCover is one of the most popular .NET code coverage solutions.
OpenCover OpenCover is a code coverage tool for .NET 2 and above (Windows OSs only), with support for 32 and 64 processes and covers both branch and sequence points. The Mono framework is not supported.
NCrunch NCrunch is an automated testing extension for Visual Studio that eases the testing process with its code coverage tools.
NDepend NDepend conveniently identifies areas of code requiring more tests and provides quality visualizations of code coverage.
AltCover An open-source coverage tool for .NET (Framework 2.0+ and Core) and Mono which includes a set of related utilities for processing and displaying the results.

.NET dependency injection containers

This is the list of all the available Dependency Injection frameworks/containers for the .NET platform:

Dependency injection container/framework Description
Microsoft built-in dependency injection framework The standard Microsoft dependency injection container is available by using the Microsoft.Extensions.DependencyInjection namespace.
Autofac Autofac is an Inversion of Control container for .NET Core, ASP.NET Core, .NET 4.5.1+, Universal Windows applications, and more.
Castle Windsor Castle Windsor is a quality and mature inversion of control container available for .NET and Silverlight.
Ninject Ninject helps you use the technique of dependency injection to break your applications into loosely coupled, highly cohesive components, and then glue them back together in a flexible manner.

.NET mocking frameworks

In this course, we covered the Moq framework. The usage of other frameworks is very similar to Moq. Therefore, upskilling yourself in any of the other mocking frameworks is easy if you understand the Moq framework. The following are the most common mocking frameworks used in .NET:

Dependency injection container/framework Description
Moq Moq (pronounced “Mock-you” or just “Mock”) is the only mocking library for .NET developed from scratch to take full advantage of .NET Linq expression trees and lambda expressions. This makes it the most productive, type-safe, and refactoring-friendly mocking library available.
NSubstitute The NSubstitute mocking framework has a succinct syntax that other frameworks seem to lack.
FakeItEasy This is a .NET dynamic fake library for creating all types of fake objects, mocks, and stubs.
JustMock A fast and flexible complete mocking tool for crafting unit tests.


Upon the completion of this lesson, you should have a firm grasp of the various testing frameworks and landscapes, as well as their relative advantages. This course provided practical experience in one framework from each set of testing, code coverage, dependency injection container, and mocking frameworks. Given that the principles within the four framework categories are the same, your knowledge in one framework is easily transferable to the others.

Get hands-on with 1200+ tech skills courses.