Skip to content

Integration Testing

Shivam edited this page Jan 17, 2022 · 1 revision

Integration tests ensure that an application's components function correctly at a level that includes the app's infrastructure and whole framework, often including the following components:

  • Database
  • File system
  • Network appliances
  • Request-response pipeline

ASP.NET Core supports integration tests using a unit test framework with a test web host and an in-memory test server.

We have used xUnit Test Project template for integration testing purpose.

NuGet Packages

We need to installthese packages from NuGet Package Manager,

  • xunit
  • xunit.runner.visualstudio
  • AspNetCore.Mvc.Testing – this package provides the TestServer and an important class WebApplicationFactory to help us bootstrap our app in-memory
  • Microsoft.EntityFrameworkCore.InMemory – In-memory database provider

We need to download Docker platform to run the integartion test cases. Click here to download it. Docker is an open source containerization platform. It enables developers to package applications into containers—standardized executable components combining application source code with the operating system (OS) libraries and dependencies required to run that code in any environment.

IntegrationTestWorkflow

Steps to run Test Cases

We have a docker-compose.yml file at the root of our repository which starts a SQL Server container for us. Now execute the below command at the root of repository,

docker-compose up 

This command builds, (re)creates, starts, and attaches to containers for a service. IntegrationTest5(cmd)

Right click on Test case application and click on Run Tests as shown below,

IntegrationTest1

Select Test in toolbar then select Run All Tests to run all test cases or Test Explorer.

IntegrationTest2

This will display the list of test case methods. Then right click on the Get_CategoriesList_ReturnsSuccessResult method and click Run, and the result will be shown as below,

IntegrationTest3

All integration test cases,

IntegrationTest4

The [Fact] attribute will be green as test case is passed. [Fact] attribute, which is used by the xUnit framework, marking them as the actual testing methods.

IntegrationTest6(fact)

CI Build Result,

Here docker-compose will start a SQL Server container for us.

IntegrationTest(Build1)

These are total integration test cases in project and the test result which is passed.

IntegrationTest(Build2)

Demo

Demo video to get the clear result view of above implemented module.

Integration.Testing.mp4
Clone this wiki locally