liveBook · Manning

Chapter 35: Testing applications with xUnit

What you will learn in chapter 35 of ASP.NET Core in Action, 3e

This introduction frames the chapter as a practical guide to creating and running isolated xUnit unit tests in .NET before extending those basics to ASP.NET Core testing.

After this chapter you will be able to

Section by section

Introduction

This introduction frames the chapter as a practical guide to creating and running isolated xUnit unit tests in .NET before extending those basics to ASP.NET Core testing.

Key terms: automated testing, manual testing, code coverage, xUnit, unit test project, isolated unit tests, .NET command-line interface (CLI), Visual Studio, currency-converter service, services

35.1 An introduction to testing in ASP.NET Core

Introduces ASP.NET Core testing, distinguishing unit and integration tests and showing how .NET tooling and framework design support both.

Key terms: .NET SDK, dotnet test, Visual Studio test runner, test project, .NET Test SDK, unit testing framework, test-runner adapter, NuGet packages, unit tests, integration tests

35.2 Creating your first test project with xUnit

This section shows how to create an xUnit test project and explains the project setup and structural requirements of its default Fact test.

Key terms: xUnit, xUnit Test Project, MSTest Project, NUnit Test Project, Visual Studio, .NET CLI, NuGet packages, Microsoft.NET.Test.Sdk, IsTestProject, MSBuild

35.3 Running tests with dotnet test

This section shows how to run xUnit tests in Visual Studio or with the dotnet test CLI command and interpret their results.

Key terms: Test Explorer, Test > Run All Tests, Run All, xUnit, exception, pass, dotnet test, .NET CLI, .NET Test SDK, solution folder

35.4 Referencing your app from your test project

This section connects an xUnit test project to an ASP.NET Core app project, describes common solution layouts, and introduces the CurrencyConverter class that subsequent tests will exercise.

Key terms: project reference, Dependencies, Reference Manager, ProjectReference, .csproj, ItemGroup, relative path, parent folder, solution file, src

35.5 Adding Fact and Theory unit tests

This section shows how to structure xUnit unit tests for typical scenarios and parameterize repeated test cases with theories.

Key terms: happy path, error path, edge cases, ConvertToGbp(), Arrange, Act, Assert, AAA, system under test, SUT, Assert.Equal(), Fact

35.6 Testing failure conditions

This section shows how to test valid edge cases and invalid inputs in xUnit, including verifying expected exceptions without making brittle implementation-dependent tests.

Key terms: edge cases, valid cases, invalid values, CurrencyConverter, ConvertToGbp, Assert.Throws, ArgumentException, lambda function, Fact, Assert

35.7 Summary

This summary recaps how to create, run, and write xUnit tests, including data-driven tests and assertions for expected outcomes or failures.

Where this is used later

Concepts explained in this chapter

← Chapter 34: Building background tasks and ser vices Chapter 36: Testing ASP.NET Core applications →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.