ASP.NET Core 5.0 API + EF Core + MSSQL example application which utilize integration testing using Docker containers for throwaway DB instance.
The integration testing implemented with help of:
- Testcontainers - is a .NET standard 2.0 library that supports NUnit and XUnit tests, providing lightweight, throwaway instances of common databases or anything else that can run in a Docker container.
- XUnit - xUnit.net is a free, open source, community-focused unit testing tool for the .NET Framework.
- TestServer - the test web host and in-memory test server, are provided or managed by the Microsoft.AspNetCore.Mvc.Testing package. Use of this package streamlines test creation and execution.
- Respawn - is a small utility to help in resetting test databases to a clean state. Instead of deleting data at the end of a test or rolling back a transaction, Respawn resets the database back to a clean checkpoint by intelligently deleting data from tables.
IntegrationContainers.API- .NET Core 5.A PIIntegrationContainers.Data- sort of Data Access Layer with EF Core Db Context , entities, migrationsIntegrationContainers.API.Tests- integration tests with fixtures setup
Before running unit tests:
-
Install docker https://docs.docker.com/get-docker/
-
Pull SQL Server image:
docker pull mcr.microsoft.com/mssql/server:2017-latest-ubuntu