How to do integration testing in ASP.Net Core

Take advantage of xUnit and ASP.Net Core’s test host package to run integration tests on your ASP.Net Core web applications

Become An Insider

Sign up now and get FREE access to hundreds of Insider articles, guides, reviews, interviews, blogs, and other premium content. Learn more.

Testing is an essential part of developing any application. There are various types of tests. Unit tests are used to check if the output of blocks or units of code conforms to the desired results. Integration tests are used to check if the different parts of the application work as expected when they are assembled together. In this article I will discuss how we can write and execute integration tests using ASP.Net Core.

Create a new ASP.Net Core project

First off, let’s create an ASP.Net Core project in Visual Studio. Assuming that .Net Core is already installed on your system, follow these steps to create an ASP.Net Core application in Visual Studio 2017.

  1. In the Visual Studio IDE, click on File > New > Project.
  2. Select “ASP.Net Core Web Application (.Net Core)” from the list of the templates displayed.
  3. Specify a name for the project.
  4. Click OK to save the project.
  5. In the “New .Net Core Web Application…” window, select “Web API.”
  6. Ensure that “Enable Docker Support” is unchecked.
  7. Select “No Authentication” as we won’t be using authentication in this example
  8. Click OK.

A new ASP.Net Core project will then be created with an example Controller to build and execute RESTful HTTP services.

To continue reading this article register now