01 02 03 04 05 Contents Background & Motivation Unit tests vs. Integration tests Difficulties in Integration tests Intro to Testcontainers A concrete example
Integration tests Unit tests vs. Integration tests Database connection External API calls Isolation Mock / Stub Unit tests External Service Integration
Latency, packet loss, unreliable network channels Network Issue Expected state or behavior doesn’t match between two ends Data Inconsistency Concurrent operation leads to unexpected behavior Race Condition Even though two modules may separately pass their own unit tests, they may still fail when combined altogether Integration tests might fail...
Real Services Docker Containers Ensure consistency across different development stages • easy to setup and teardown • provide a clean and complete instance Intro to Testcontainers A testing library that supports integration tests with real services wrapped in Docker containers ※ Source from ︓ • https://testcontainers.com/guides/introducing-testcontainers/ Include external dependencies within our tests • database layer • stream processing • any docker images
Workflow of Testcontainers • Before Tests: • Launch required services. E.g., databases, external dependencies. • During Tests: • Your tests will run using these containerized services. • After Tests: • destroying those started containers gracefully without interference. ※ Source from : • https://testcontainers.com/guides/introducing-testcontainers/
Benefits from using Testcontainers • No pre-provisioned infra needed • No data conflict issues • Local test support • Support multiple languages, including .NET, Go, NodeJS, and Python ※ Source from : • https://testcontainers.com/guides/introducing-testcontainers/
Here, we perform integration tests with Testcontainers using TypeScript & Jest A concrete example Utilize Testcontainers with lightweight API Containers being launched during test running