https://github.com/iiroki/samples-testcontainers
Testcontainers samples with various languages.
https://github.com/iiroki/samples-testcontainers
docker dotnet nodejs testcontainers testing typescript
Last synced: 3 months ago
JSON representation
Testcontainers samples with various languages.
- Host: GitHub
- URL: https://github.com/iiroki/samples-testcontainers
- Owner: iiroki
- License: mit
- Created: 2024-04-20T12:49:59.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T16:09:34.000Z (about 2 years ago)
- Last Synced: 2025-01-24T01:46:20.674Z (over 1 year ago)
- Topics: docker, dotnet, nodejs, testcontainers, testing, typescript
- Language: C#
- Homepage:
- Size: 75.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Samples: Testcontainers
[](https://github.com/iiroki/samples-testcontainers/actions/workflows/dotnet-test.yml)
[](https://github.com/iiroki/samples-testcontainers/actions/workflows/node-test.yml)
[**Testcontainers**](https://testcontainers.com/) 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.
## Tools
The samples in the repository depend on the following tools:
- Docker (required by Testcontainers)
- Language-specific SDKs (see ["Languages"](#languages) below)
## Languages
### .NET
**Version:** .NET 8
.NET samples are located under [`dotnet/`](./dotnet/).
#### Structure
The sample .NET solution consist of three projects:
- **[`Samples.Testcontainers`](./dotnet/Samples.Testcontainers/):** The actual project that's tested
- **[`Samples.Testcontainers.Tests.Nunit`](./dotnet/Samples.Testcontainers.Tests.Nunit/):**
[NUnit](https://nunit.org/) samples:
- Postgres
- **[`Samples.Testcontainers.Tests.Xunit`](./dotnet/Samples.Testcontainers.Tests.Xunit/):**
[xUnit](https://xunit.net/) 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!
#### Commands
- Run all tests from the solution:
```bash
dotnet test
```
- Run tests from a specific project:
```bash
dotnet test
```
#### Notes
- The samples utilize `InternalsVisibleToAttribute` to expose internal objects to the test projects,
see [`Samples.Testcontainers.csproj`](./dotnet/Samples.Testcontainers/Samples.Testcontainers.csproj) for the usage.
### Node/TypeScript
**Version:** Node 20
Node samples are located under [`node/`](./node/).
#### Structure
The Node project contains a simple Postgres example with Testcontainers.
#### Commands
Run all tests:
```bash
npm test
```
## CI
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`](./.github/workflows/):
- **[`dotnet-test.yml`](./.github/workflows/dotnet-test.yml):** .NET CI pipeline
- Runs NUnit and xUnit tests separately and then together at the same time.
- **[`node-test.yml`](./.github/workflows/node-test.yml):** Node CI pipeline
- Runs tests with Jest.