Testcontainers is an open source framework for running test dependencies as Docker containers.
The repository contains few samples on how to get started with Testcontainers with various languages.
The samples in the repository depend on the following tools:
- Docker (required by Testcontainers)
- Language-specific SDKs (see "Languages" below)
Version: .NET 8
.NET samples are located under dotnet/
.
The sample .NET solution consist of three projects:
Samples.Testcontainers
: The actual project that's testedSamples.Testcontainers.Tests.Nunit
: NUnit samples:- Postgres
Samples.Testcontainers.Tests.Xunit
: xUnit samples:- Postgres
- Blob Storage (= Azurite)
- Postgres + Blob Storage (both used at the same time)
Only test projects have references to the tested project, not the other way around!
-
Run all tests from the solution:
dotnet test
-
Run tests from a specific project:
dotnet test <project_name>
- The samples utilize
InternalsVisibleToAttribute
to expose internal objects to the test projects, seeSamples.Testcontainers.csproj
for the usage.
Version: Node 20
Node samples are located under node/
.
The Node project contains a simple Postgres example with Testcontainers.
Run all tests:
npm test
The repository also demonstrates how to use Testcontainers in CI pipelines with GitHub Actions.
Integrating Testcontainers to CI pipelines is as almost as easy it can get, since the tests can just be executed with the chosen language's standard test commands without any extra configuration!
The GitHub Actions CI pipelines are located under .github/workflows
:
dotnet-test.yml
: .NET CI pipeline- Runs NUnit and xUnit tests separately and then together at the same time.
node-test.yml
: Node CI pipeline- Runs tests with Jest.