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
  1. NUnit

Creating a NUnit test project

Before we go deeper into NUnit details, let’s see how to quickly create a unit test project that uses NUnit.

NUnit has good integration with both Microsoft Visual Studio and JetBrains ReSharper but the fastest way to create a test project is by using the dotnet new utility that comes with the .NET Core SDK.

Before you can proceed, you need to install the template. You can quickly do so by executing the following command in your preferred shell.

dotnet new -i NUnit3.DotNetNew.Template

Once you have installed the template, you can simply create a new NUnit-based unit test project by executing

dotnet new nunit

By default, the project will be created in the current directory and it will be named after its name. Optionally, you can provide the name of the project: this name will also be used to create a directory for the project.

dotnet new nunit -n MyFirstTestProject

The newly created project will consist of a project file and a sample unit test class.

PreviousQuick glance at NUnitNextAnatomy of a test fixture

Last updated 4 years ago