6 Testing ASP.NET Core applications

 

This chapter covers

  • Creating unit tests projects for ASP.NET Core application
  • Writing and running unit tests
  • Isolating application components for testing
  • Simplifying component isolation with a mocking package

In this chapter, I demonstrate how to unit test ASP.NET Core applications. Unit testing is a form of testing in which individual components are isolated from the rest of the application so their behavior can be thoroughly validated. ASP.NET Core has been designed to make it easy to create unit tests, and there is support for a wide range of unit testing frameworks. I show you how to set up a unit test project and describe the process for writing and running tests. Table 6.1 provides a guide to the chapter.

6.1 Preparing for this chapter

6.1.1 Opening the project

6.1.2 Selecting the HTTP port

6.1.3 Enabling the MVC Framework

6.1.4 Creating the application components

6.1.5 Running the example application

6.2 Creating a unit test project

6.3 Writing and running unit tests

6.3.1 Running tests with the Visual Studio Test Explorer

6.3.2 Running tests with Visual Studio Code

6.3.3 Running tests from the command line

6.3.4 Correcting the unit test

6.3.5 Isolating components for unit testing

6.3.6 Using a mocking package

6.3.7 Creating a mock object

Summary