Description
Testcontainers-Go is a Go package that makes it simple to create and clean up container-based dependencies for automated integration/smoke tests. The clean, easy-to-use API enables developers to programmatically define containers that should be run as part of a test and clean up those resources when the test is done.
Testcontainers-go alternatives and similar packages
Based on the "Testing" category.
Alternatively, view testcontainers-go alternatives based on common mentions on social networks and blogs.
-
Testify
A toolkit with common assertions and mocks that plays nicely with the standard library -
chromedp
A faster, simpler way to drive browsers supporting the Chrome DevTools Protocol. -
gomock
GoMock is a mocking framework for the Go programming language. -
GoConvey
Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go. -
go-sqlmock
Sql mock driver for golang to test database interactions -
gotests
Automatically generate Go test boilerplate from your source code. -
realize
Realize is the #1 Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading. -
selenoid
Selenium Hub successor running browsers within containers. Scalable, immutable, self hosted Selenium-Grid on any platform with single binary. -
Looking for Maintainer
Selenium/Webdriver client for Go -
hoverfly
Lightweight service virtualization/ API simulation / API mocking tool for developers and testers -
playwright-go
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API. -
gnomock
Test your code without writing mocks with ephemeral Docker containers 📦 Setup popular services with just a couple lines of code ⏱️ No bash, no yaml, only code 💻 -
go-vcr
Record and replay your HTTP interactions for fast, deterministic and accurate tests -
testfixtures
Ruby on Rails like test fixtures for Go. Write tests against a real database -
counterfeiter
A tool for generating self-contained, type-safe test doubles in go -
goc
A Comprehensive Coverage Testing System for The Go Programming Language -
embedded-postgres
Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test -
cdp
Package cdp provides type-safe bindings for the Chrome DevTools Protocol (CDP), written in the Go programming language. -
Mmock
Mmock is an HTTP mocking application for testing and fast prototyping -
minimock
Powerful mock generation tool for Go programming language -
gotest.tools
A collection of packages to augment the go testing package and support common patterns. -
testza
Full-featured test framework for Go! Assertions, fuzzing, input testing, output capturing, and much more! 🍕 -
ggr
A lightweight load balancer used to create big Selenium clusters -
go-testdeep
Extremely flexible golang deep comparison, extends the go testing package, tests HTTP APIs and provides tests suite
Free Global Payroll designed for tech teams
Do you think we are missing an alternative of Testcontainers-go or a related project?
README
Testcontainers-Go is a Go package that makes it simple to create and clean up container-based dependencies for automated integration/smoke tests. The clean, easy-to-use API enables developers to programmatically define containers that should be run as part of a test and clean up those resources when the test is done.
Here's an example of a test that spins up an NGINX container validates that it returns 200 for the status code:
package main
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)
type nginxContainer struct {
testcontainers.Container
URI string
}
func setupNginx(ctx context.Context) (*nginxContainer, error) {
req := testcontainers.ContainerRequest{
Image: "nginx",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForHTTP("/"),
}
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
return nil, err
}
ip, err := container.Host(ctx)
if err != nil {
return nil, err
}
mappedPort, err := container.MappedPort(ctx, "80")
if err != nil {
return nil, err
}
uri := fmt.Sprintf("http://%s:%s", ip, mappedPort.Port())
return &nginxContainer{Container: container, URI: uri}, nil
}
func TestIntegrationNginxLatestReturn(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
ctx := context.Background()
nginxC, err := setupNginx(ctx)
if err != nil {
t.Fatal(err)
}
// Clean up the container after the test is complete
defer nginxC.Terminate(ctx)
resp, err := http.Get(nginxC.URI)
if resp.StatusCode != http.StatusOK {
t.Fatalf("Expected status code %d. Got %d.", http.StatusOK, resp.StatusCode)
}
}
Cleaning up your environment after test completion should be accomplished by deferring the container termination, e.g
defer nginxC.Terminate(ctx)
. Reaper (Ryuk) is also enabled by default to help clean up.
Documentation
More information about TestContainers-Go can be found in [./docs](./docs), which is rendered at golang.testcontainers.org.