Unit Testing in C#
  • Unit testing in C#
  • Unit testing
    • What to test
    • When to test
    • Qualities of a good unit test suite
    • Qualities of a good unit test
    • Dealing with dependencies
    • Running the tests
  • NUnit
    • Quick glance at NUnit
    • Creating a NUnit test project
    • Anatomy of a test fixture
    • Lifecycle of a test fixture
    • Assertions
    • Asynchronous executions
    • Parameterized tests
    • Assumptions
    • Describing your tests
  • Moq
    • Quick glance at Moq
    • Method arguments
    • Method calls
    • Properties
    • Results
    • Callbacks
    • Exceptions
    • Events
    • Verifications
    • Base class
    • Mock customization
    • Implicit mocks
    • Mock repository
    • Custom matchers
    • Multiple interfaces
    • Protected members
    • Generic methods
    • Delegates
  • AutoFixture
    • Quick glance at AutoFixture
    • Fixture
    • Create and Build
    • Type customization
    • Data annotations
    • Default configurations
    • Building custom types
    • Relays
    • Tricks
    • Idioms
    • Integration with NUnit
    • Integration with Moq
    • Combining AutoFixture with NUnit and Moq
    • Extending AutoFixture
  • Advanced topics
    • Testing HttpClient
Powered by GitBook
On this page

Was this helpful?

  1. NUnit

Quick glance at NUnit

NUnit is an open-source unit testing framework for the .NET platform. It supports multiple runtimes like .NET Framework, .NET Core, Mono and Xamarin.

As the name suggests, it’s part of the xUnit family of testing frameworks and it shares with them the basic concepts and architecture.

Here are some of the basic concepts that can be found in NUnit

  • A test fixture is a class marked with the TestFixture attribute and contains one or more tests. Test fixtures can be configured with setup and teardown steps that must be performed for each test.

  • A test is a method marked with the Test attribute

  • A test runner is an application responsible for executing all the tests and reporting the test results

NUnit has a strong support for data driven tests: the same unit test can be run with multiple input data. We will see how we can use this to create leaner and more effective unit tests.

Finally, to reduce the amount of code repeated for each unit test, NUnit offers different utilities to set-up and tear-down the execution context.

Note: at the time of writing, the latest version of NUnit is the 3.12.

PreviousRunning the testsNextCreating a NUnit test project

Last updated 4 years ago

Was this helpful?