Testing

Unit testing frameworks, assertion libraries, mocking, and test-driven development methodology.

Pages

  • NUnitNUnit constraint-based assertion model and test framework for .NET
  • xUnitxUnit.net free, open-source, community-focused unit testing tool for .NET
  • MSTestMSTest unit testing framework for Visual Studio

TDD and Supporting Tools

Test-Driven Development methodology: write tests first, then implement to make them pass.

Key properties of a good unit test: atomic, deterministic, repeatable, order-independent, fast, and easy to set up.

Recommended reading:

  • Growing Object-Oriented Software, Guided by Tests — Freeman & Pryce (2010)
  • Test Driven Development By Example — Kent Beck (2002)

Mocking and assertion libraries:

  • MOQ (Moq) — mocking framework for .NET using lambda-based setup and verification
  • FluentAssertions — fluent assertion library for expressive, readable test assertions
  • Microsoft.AspNetCore.TestHost — integration testing host for ASP.NET Core applications
  • OpenCover — open-source code coverage tool for all .NET frameworks

FakeItEasy

FakeItEasy — the easy mocking library for .NET 1.

  • Throwing exceptions 2
  • MustHaveHappened with A<T>.That.Contains for collection argument matching 3

«


Table of contents