Slide 1

Slide 1 text

我覺得草莓尬⾁粽不⾏:從草 莓⾁粽了解整合測試的重要性 Brian Kuo, TECH FRESH @ LINE TRAVEL Backend

Slide 2

Slide 2 text

⾁粽 OK!草莓也 OK! ※ Source from ︓ • https://reurl.cc/RzXA3e • https://removal.ai/ • https://www.gomaji.com/blog/%E7%AB%AF%E5%8D%88%E8%82%89%E7%B2%BD/

Slide 3

Slide 3 text

但草莓⾁粽… 單獨都好吃,合起來怎麼就變這麼奇怪? ※ Source from ︓ • https://reurl.cc/RzXA3e • https://removal.ai/ • https://www.gomaji.com/blog/%E7%AB%AF%E5%8D%88%E8%82%89%E7%B2%BD/

Slide 4

Slide 4 text

01 02 03 04 05 Contents Background & Motivation Unit tests vs. Integration tests Difficulties in Integration tests Intro to Testcontainers A concrete example

Slide 5

Slide 5 text

Integration tests Unit tests vs. Integration tests Database connection External API calls Isolation Mock / Stub Unit tests External Service Integration

Slide 6

Slide 6 text

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...

Slide 7

Slide 7 text

Historic Implementations of Integration tests Pre-provisioned Infrastructure Setup Cost Test Pollution In-memory Database Service Challenges in maintaining an “Integration Testing Environment” Difficulties in Integration tests Feature Limitation Slow Feedback Cycle Testcontainers solves these issues! ※ Source from ︓ • https://testcontainers.com/guides/introducing-testcontainers/ • https://www.flaticon.com/

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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/

Slide 10

Slide 10 text

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/

Slide 11

Slide 11 text

Here, we perform integration tests with Testcontainers using TypeScript & Jest A concrete example Utilize Testcontainers with lightweight API Containers being launched during test running

Slide 12

Slide 12 text

Let’s see how it works in reality! Demo video

Slide 13

Slide 13 text

THANK YOU