-
Notifications
You must be signed in to change notification settings - Fork 0
Integration Testing
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.
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.
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.
Right click on Test case application and click on Run Tests as shown below,
Select Test in toolbar then select Run All Tests to run all test cases or Test Explorer.
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,
All integration test cases,
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.
CI Build Result,
Here docker-compose will start a SQL Server container for us.
These are total integration test cases in project and the test result which is passed.
Demo video to get the clear result view of above implemented module.