$30 off During Our Annual Pro Sale. View Details »

我覺得草莓尬肉粽不行: 從草莓肉粽了解整合測試的重要性

我覺得草莓尬肉粽不行: 從草莓肉粽了解整合測試的重要性

活動:LINE Developers Meetup 開發者小聚 #18 - TECH FRESH 畢業展
活動頁面:https://linegroup.kktix.cc/events/20230627-tech-fresh-gratudation
講者:Brian Kuo, TECH FRESH @ LINE TRAVEL

LINE Developers Taiwan
PRO

July 02, 2023
Tweet

More Decks by LINE Developers Taiwan

Other Decks in Technology

Transcript

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

    View Slide

  2. ⾁粽 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/

    View Slide

  3. 但草莓⾁粽…
    單獨都好吃,合起來怎麼就變這麼奇怪?
    ※ 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/

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  13. THANK YOU

    View Slide