All Projects → isen-ng → testcontainers-dotnet

isen-ng / testcontainers-dotnet

Licence: MIT license
dotnet port of testcontainers-java

Programming Languages

C#
18002 projects
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to testcontainers-dotnet

kekiri
A .NET framework that supports writing low-ceremony BDD tests using Gherkin language
Stars: ✭ 19 (-13.64%)
Mutual labels:  xunit, nunit
FakeItEasy.AutoFakeIt
A very simple, yet flexible, "AutoFaker" for FakeItEasy to easily auto generate classes with faked dependencies.
Stars: ✭ 15 (-31.82%)
Mutual labels:  xunit, nunit
Cake
🍰 Cake (C# Make) is a cross platform build automation system.
Stars: ✭ 3,154 (+14236.36%)
Mutual labels:  xunit, nunit
bUnit
bUnit is a testing library for Blazor components that make tests look, feel, and runs like regular unit tests. bUnit makes it easy to render and control a component under test’s life-cycle, pass parameter and inject services into it, trigger event handlers, and verify the rendered markup from the component using a built-in semantic HTML comparer.
Stars: ✭ 857 (+3795.45%)
Mutual labels:  xunit, nunit
Specflow
#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
Stars: ✭ 1,827 (+8204.55%)
Mutual labels:  xunit, nunit
allure-nunit
Archived - Allure adapter for NUnit framework.
Stars: ✭ 45 (+104.55%)
Mutual labels:  nunit
toolbox
dein ToolBox - C# .Net Library with utilities like: command line, files, log, platform, shell, system, transform and validation [ Win+Mac+Linux ]
Stars: ✭ 46 (+109.09%)
Mutual labels:  xunit
Bats Core
Bash Automated Testing System
Stars: ✭ 2,820 (+12718.18%)
Mutual labels:  xunit
Fluentassertions
A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, .NET Core 2.1 and 3.0, as well as .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.
Stars: ✭ 2,449 (+11031.82%)
Mutual labels:  xunit
ArchitectNow.ApiStarter
Sample ASP.NET Core 2 API Setup used by ArchitectNow for corresponding workshop presentations
Stars: ✭ 35 (+59.09%)
Mutual labels:  xunit
xharness
C# command line tool for running tests on Android / iOS / tvOS devices and simulators
Stars: ✭ 123 (+459.09%)
Mutual labels:  xunit
MinimalApi
ASP.NET Core 7.0 - Minimal API Example - Todo API implementation using ASP.NET Core Minimal API, Entity Framework Core, Token authentication, Versioning, Unit Testing, Integration Testing and Open API.
Stars: ✭ 156 (+609.09%)
Mutual labels:  xunit
xunit-to-junit
This Extensible Stylesheet Language Transformations can transform a xUnit.net v2 XML test results file into a JUnit test results file.
Stars: ✭ 21 (-4.55%)
Mutual labels:  xunit
resharper-xunit-templates
ReSharper Live Templates for xUnit.net
Stars: ✭ 18 (-18.18%)
Mutual labels:  xunit
xunit.testlogger
XUnit logger for vstest platform
Stars: ✭ 65 (+195.45%)
Mutual labels:  xunit
NBi
NBi is a testing framework (add-on to NUnit) for Business Intelligence and Data Access. The main goal of this framework is to let users create tests with a declarative approach based on an Xml syntax. By the means of NBi, you don't need to develop C# or Java code to specify your tests! Either, you don't need Visual Studio or Eclipse to compile y…
Stars: ✭ 102 (+363.64%)
Mutual labels:  nunit
MsCoreOne
MsCoreOne is a simple Ecommerce with using many technologies such as .NET 5, Entity Framework Core 5, React 16.13 with modern Clean Architecture, Domain-Driven Design, CQRS, SOLID, Identity Server 4, Blazor. It will focus on resolving the problems always see in the process to develop projects.
Stars: ✭ 77 (+250%)
Mutual labels:  xunit
XunitContext
Extends xUnit to expose extra context and simplify logging
Stars: ✭ 127 (+477.27%)
Mutual labels:  xunit
ParallelTestingSample-dotnet-core
Sample for running dotnet core tests in parallel across multiple agents in Azure DevOps
Stars: ✭ 19 (-13.64%)
Mutual labels:  nunit
spring-boot-tc-mysql
Sample Spring Boot application that uses MySQL to perform integration tests by using TestContainer.
Stars: ✭ 21 (-4.55%)
Mutual labels:  test-containers

TestContainers dotnet

codecov Sonarcloud Status Donation

Testcontainers is a dotnet 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.

Uses common Microsoft dependency injection patterns, app and host settings, and Microsoft Extensions Logging (MEL).

This is a port of testcontainers-java for dotnet.

Build statuses

Linux build status


Feature parity

Linux environment

  • Container management
  • Docker providers
    • Unix socket
    • Environment
  • Image management
    • Pulling from public repo
    • Building from docker file
  • Network management
    • User defined networks
    • Network aliases
  • Ryuk resource reaper

Linux containers on Windows (LCOW) environment

  • Container management
  • Docker providers
    • Npipe
    • Environment
  • Image management
    • Pulling from public repo
    • Building from docker file
  • Network management
    • User defined networks
    • Network aliases
  • Ryuk resource reaper
  • [Need help] Classic LCOW CI on Win10 (GUI) environment
    • Requires the GUI version of Docker Desktop for Windows

Experimental LCOW on Windows environment

  • Not supported
    • Primarily because this experimental feature does not allow mounting of the docker socket/npipe into a container
    • More info

Built-in containers

Container Readme Version
Generic Container -- Generic
MsSql Container README MySql
PostgreSql Container README PostgreSql
ArangoDb Container README ArangoDb
Mysql Container README MySql

Example code

For more examples, see integration tests

Start a container by pulling the image from a remote repository

var container = new ContainerBuilder<GenericContainer>()
    .ConfigureHostConfiguration(builder => builder.AddInMemoryCollection()) // host settings
    .ConfigureAppConfiguration((context, builder) => builder.AddInMemoryCollection()) // app settings
    .ConfigureDockerImageName(PlatformSpecific.TinyDockerImage)
    .ConfigureLogging(builder => builder.AddConsole()) // Microsoft extensions logging
    .ConfigureContainer((context, container) =>
    {
        // add labels
        container.Labels.Add(CustomLabel.Key, CustomLabel.Value);

        // add environment labels
        container.Env[InjectedEnvVar.Key] = InjectedEnvVar.Value;

        // add exposed ports (automatically mapped to higher port
        container.ExposedPorts.Add(ExposedPort);

        /*
         to do something like `docker run -p 2345:34567 alpine:latest`,
         both expose port and port binding must be set
         */
        container.ExposedPorts.Add(PortBinding.Key);
        container.PortBindings.Add(PortBinding.Key, PortBinding.Value);

        // add bind mounts
        container.BindMounts.Add(new Bind
        {
            HostPath = HostPathBinding.Key,
            ContainerPath = HostPathBinding.Value,
            AccessMode = AccessMode.ReadOnly
        });

        // set working directory
        container.WorkingDirectory = WorkingDirectory;

        // set command to run
        container.Command = PlatformSpecific.ShellCommand(
                $"{PlatformSpecific.Touch} {FileTouchedByCommand}; {PlatformSpecific.Shell}")
            .ToList();
    })
    .Build();

Start a container by building the image from a Dockerfile

var image = new ImageBuilder<DockerfileImage>()
    .ConfigureHostConfiguration(builder => builder.AddInMemoryCollection()) // host settings
    .ConfigureAppConfiguration((context, builder) => builder.AddInMemoryCollection()) // app settings
    .ConfigureLogging(builder => builder.AddConsole()) // Microsoft extensions logging
    .ConfigureImage((context, image) =>
    {
        image.DockerfilePath = "Dockerfile";
        image.DeleteOnExit = false;

        // add the Dockerfile into the build context
        image.Transferables.Add("Dockerfile", new MountableFile(PlatformSpecific.DockerfileImagePath));
        // add other files required by the Dockerfile into the build context
        image.Transferables.Add(".", new MountableFile(PlatformSpecific.DockerfileImageContext));
    })
    .Build();

var container = new ContainerBuilder<GenericContainer>()
    .ConfigureDockerImage(image)
    .ConfigureHostConfiguration(builder => builder.AddInMemoryCollection()) // host settings
    .ConfigureAppConfiguration((context, builder) => builder.AddInMemoryCollection()) // app settings
    .ConfigureLogging(builder => builder.AddConsole()) // Microsoft extensions logging
    .ConfigureContainer((h, c) =>
    {
        c.ExposedPorts.Add(80);
    })
    .Build();

or

var container = new ContainerBuilder<GenericContainer>()
    .ConfigureDockerImage((hostContext, builderContext) =>
    {
        return new ImageBuilder<DockerfileImage>()
            // share the app/host config and service collection from the parent builder context
            .WithContextFrom(builderContext)
            .ConfigureImage((context, image) =>
            {
                image.DeleteOnExit = false;
                image.BasePath = PlatformSpecific.DockerfileImageContext;

                // add the Dockerfile as like the command line `-f <path to dockerfile`
                image.DockerfilePath = "Dockerfile";
                image.Transferables.Add("Dockerfile", new MountableFile(PlatformSpecific.DockerfileImagePath));

                // add other files required by the Dockerfile into the build context
                image.Transferables.Add("folder1", new MountableFile(DockerfileImageTransferableFolder));
            })
            .Build();
    })
    .ConfigureHostConfiguration(builder => builder.AddInMemoryCollection()) // host settings
    .ConfigureAppConfiguration((context, builder) => builder.AddInMemoryCollection()) // app settings
    .ConfigureLogging(builder => builder.AddConsole()) // Microsoft extensions logging
    .ConfigureContainer((h, c) =>
    {
        c.ExposedPorts.Add(80);
    })
    .Build();

Start a container with a new network

var container = new ContainerBuilder<GenericContainer>()
    .ConfigureNetwork((hostContext, builderContext) =>
    {
        return new NetworkBuilder<UserDefinedNetwork>()
            // share the app/host config and service collection from the parent builder context
            .WithContextFrom(builderContext)
            .ConfigureNetwork((context, network) =>
            {
                // be careful when setting static network names
                // if they already exists, the existing network will be used
                // otherwise, the default NetworkName is a random string
                network.NetworkName = "my_network"
            })
            .Build();
    })
    .ConfigureHostConfiguration(builder => builder.AddInMemoryCollection()) // host settings
    .ConfigureAppConfiguration((context, builder) => builder.AddInMemoryCollection()) // app settings
    .ConfigureLogging(builder => builder.AddConsole()) // Microsoft extensions logging
    .ConfigureContainer((h, c) =>
    {
        c.ExposedPorts.Add(80);
    })
    .Build();

Configuring TestContainers-dotnet

There are some configurations to testcontainers-dotnet that cannot be performed in code or injected. These configuration can be set in environment variables before the first instance of your container is built.

Variable Default Description
REAPER_DISABLED (not-set) When set to 1 or true, disables starting of the reaper container
REAPER_IMAGE quay.io/testcontainers/ryuk:0.2.3 Change which container image to use for reaper
REAPER_PORT (not-set) Use the given port for reaper instead of a dynamic port
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].