liveBook · Manning

Test project

As explained in ASP.NET Core in Action, 3e

A unit test app is a .NET console application project that contains automated tests and their test dependencies.

A test project is a .NET console application that contains automated tests and their dependencies. Tests run application code in isolation and check whether it behaves as expected. section 35.1

A typical test project depends on three components:

  • The .NET Test SDK, which connects testing with the .NET SDK. section 35.1
  • A testing framework such as xUnit, NUnit, Fixie, or MSTest. section 35.1
  • A test-runner adapter that lets dotnet test and Visual Studio execute the tests. section 35.1

Create and run an xUnit test project

Create an xUnit project with dotnet new xunit. The project includes Microsoft.NET.Test.Sdk, xunit, and xunit.runner.visualstudio packages. Run its tests with dotnet test or use Test Explorer in Visual Studio; both approaches produce the same results. Use [Fact] for a public, parameterless test and [Theory] when the test accepts parameters and repeats with different data. section 35.7 section 35.1

<ItemGroup>
 <ProjectReference
   Include="..\..\src\ExchangeRates.Web\ExchangeRates.Web.csproj" />
</ItemGroup>

Add a ProjectReference from the test project to the application project so tests can exercise its classes. section 35.4

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines project components, creation, execution, test attributes, and application references without addressing broader testing strategy.
Examples
Uses xUnit creation commands, Fact and Theory methods, Test Explorer, dotnet test, and ProjectReference configuration.
What you can do after
Operate test projects with dotnet test or Test Explorer and configure them to test application classes.
How it connects
Connects unit tests with the .NET SDK, xUnit, MSTest, NUnit, integration tests, NuGet packages, and Visual Studio Test Explorer.

Also explained in

Compare how 2 books explain test project →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.