/testcontainers-aspnet-integration-tests

ASP.NET Core integration tests with Testcontainers

Primary LanguageC#MIT LicenseMIT

testcontainers-aspnet-integration-tests

Build status

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:

  1. 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.
  2. XUnit - xUnit.net is a free, open source, community-focused unit testing tool for the .NET Framework.
  3. 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.
  4. 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.

Project structure

  1. IntegrationContainers.API - .NET Core 5.A PI
  2. IntegrationContainers.Data - sort of Data Access Layer with EF Core Db Context , entities, migrations
  3. IntegrationContainers.API.Tests - integration tests with fixtures setup

Setup

Before running unit tests:

  1. Install docker https://docs.docker.com/get-docker/

  2. Pull SQL Server image:

    docker pull mcr.microsoft.com/mssql/server:2017-latest-ubuntu