Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
testcontainers のススメ
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Sugar Sato
December 10, 2024
Programming
540
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
testcontainers のススメ
Sugar Sato
December 10, 2024
More Decks by Sugar Sato
See All by Sugar Sato
AIと共に生きる技術選定 2026
sgash708
0
330
Bref でサービスを運用している話
sgash708
0
340
tool ディレクティブを導入してみた感想
sgash708
1
300
DeepWiki で Go をもっと好きになろう
sgash708
0
1.1k
環境変数ライブラリ選手権
sgash708
0
320
はじめての Go * WASM * OCR
sgash708
1
450
もう僕は OpenAPI を書きたくない
sgash708
6
2.7k
【懺悔】1年目 EM の失敗から学ぼう
sgash708
0
260
「僕ら」のテストに対する向き合い方
sgash708
5
550
Other Decks in Programming
See All in Programming
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
500
AHC070解法紹介
eijirou
0
130
すこし踏み込む CancellationToken
htkym
2
870
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
270
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
560
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.4k
iOSDC2026登壇資料.pdf
riofujimon
0
180
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
2
300
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
750
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
310
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
500
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
190
Featured
See All Featured
Balancing Empowerment & Direction
lara
6
1.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
550
The Curse of the Amulet
leimatthew05
3
15k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
370
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
410
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
280
Color Theory Basics | Prateek | Gurzu
gurzu
1
470
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
430
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
440
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
480
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
66k
Transcript
testcontainers のススメ Go Connect #4 2024. 12. 10
2 自己紹介 Sugar Sato (@satoIsSugar) • 2023年 BuySell Technologies入社 •
基盤チーム所属(Portal/Account/Approval) PjM ◦ アソシエイトマネージャー • Go / Angular / Serverless ◦ Go歴: Go 年目くらい • 熱帯植物 ◦ ビカクシダ • 猫 ◦ Lambda (♀ 2才)
3 プロダクト群「バイセルリユースプラットフォーム Cosmos」の開発が進行中 リユースに必要なすべての機能を提供する 「リユースプラットフォーム Cosmos」の開発が進行中です。 Cosmosを活用して、バイセルグループ全体での業務効率改善やデータドリブン経営の深化を目指しています。 リユースプラットフォーム Cosmos 自社開発のリユース特化業務基幹システムでありサービス群の集合体
買取申込 買取・査定 在庫管理 販売 多様なチャネルで収益最大化 CRM -顧客対応- 買取種別に応じた最適なシステム構築 Visit -訪問買取 - Store -店舗買取 - Promas -商材マスタ - Appraisal -専門査定 - Stock -在庫管理 - EXS -販売管理 - Core -会員管理- Portal -データ利用- Pocket -データ基盤- 買取 専門チームによる真贋・査定と連携 査定 申込 効率的な顧客対応 在庫 在庫管理の最適・効率化 販売 データ 各事業プロセスにある データを一元管理 :基幹システム
本題に入りまして、、、 「みんなテストは好きか〜?」
好きだ〜🙌 好きじゃないぞ〜! 正直どっちでもない ど ち らか とい え ば 好
きか も テストこそ正 義 ! 逃げられない戦いがそこにある できることなら逃げたい カバ レ ッジ ! カバレッジ! mock!! testable!! カ バ レ ッジ ! カバレッジ! そ の 術 は オ レに 効 く テ ス タ ブ ル モック! モック! 0!! C1!!
あれ? 先月そんな話してたような?
またもやテスト関連の話をしようと思います ※ 取り組み話多め
01 技術選定の背景 02 testcontainers とは 03 まとめ 目次 Index
技術選定の背景 01
そもそもなぜ必要なの?
11 なぜ必要だったか • テスト時間の短縮 • Cloud Functions のテスト ◦ 複雑な
SQL クエリに対してテストしたい 実際のリソースでテストできて 当時に勢いがあった ory/dockertest が良さそうかも 背景
12 ory/dockertest とは “Dockertest helps you boot up ephemeral docker
images for your Go tests with minimal work.” 特徴 • 「最小限の作業で一時的なDockerイメージを起動」 • イメージさえあれば簡単に起動できる • シンプルな書き心地 • リリース頻度が高くない... ◦ あんまりメンテされてない? ◦ 後に切り替えることへのきっかけに... • テスト終わってもコンテナが残る ◦ Purge を自分でする必要
13 ory/dockertest とは
14 ory/dockertest とは
15 テスト時間の短縮 ory/dockertest 導入前後のテスト実行時間比較 導入前 • Hasura を使っていた ◦ PostgreSQL
コンテナ↑ ◦ remote schema コンテナ↑ ◦ Hasura コンテナ↑ ◦ Hasura CLI でマイグレーション ※ Hasura: PostgreSQL サーバーから自動的に GraphQL サーバーを建てるもの 導入後 • Hasura や Remote Schema 環境の依存 度↓ ◦ 但し Hasura のマイグレーション ファイルを使う ◦ そのため完全に依存をなくすのは厳 しい 7〜8分 程度時間がかかっていた 2〜3分 程度になった!
そんなわけで ory/dockertest を「当初」に選定された
なぜ ory/dockertest から 乗り換える必要があったの?
18 dependabot が PR 作成 ory/dockertest から乗り換える理由 PR マージ Cloud
Functions のテストが失敗しだす 原因調査 dockertest で依存している docker パッケージ更新が原因... STEP1 STEP2 STEP3 STEP4 STEP5 時系列
19 dependabot が PR 作成 ory/dockertest から乗り換える理由 PR マージ Cloud
Functions のテストが失敗しだす 原因調査 dockertest で依存している docker パッケージ更新が原因... STEP1 STEP2 STEP3 STEP4 STEP5 docker パッケージの更新により 使えないメソッドや型が出てきた? ※ v3.11.0 のリリースで改善済み 時系列
20 ory/dockertest から乗り換える理由 docker のバージョンに 対応できない リリース頻度が遅く メンテナンス性の問題がある 要因1 要因2
ory/dockertest を脱却して他のパッケージを使おう! 方針
testcontainers とは 02
22 testcontainers とは “Unit tests with real dependencies” 特徴 活用事例
• Elastic - Testing of the APM Server, and E2E testing for Beats • Telegraf - Integration testing the plugin-driven server agent for collecting & reporting metrics • Intel - Reference implementation design E2E testing for microservice-based solutions • OpenTelemetry - Integration testing of the OpenTelemetry Collector receivers • e2e や integration test に使われる • 企業スポンサー多数 • リリース頻度が高い • SDK が豊富 (Go / Java / Node / Ruby / Python / Rust) • examples が豊富 ◦ 注) ちょっと探しづらい... ◦ godoc から見るのがおすすめ • ory/dockertest に比べると書くことが多い
23 testcontainers とは
24 testcontainers とは
25 testcontainers とは
26 testcontainers moduleから使う
27 testcontainers とは testcontainers/testcontainers-go vs ory/dockertest testcontainers: 3707↑ dockertest: 4187↑
28 比較されることも... • 『dockertest のススメ』 ◦ “追記: 2024-07-20 Testcontainers を使いましょう”
• 『GoにおけるDBテスト dockertest vs testcontainers 比較してみた』 ◦ “dockertest の方が実行速度がはやい?” testcontainers とは testcontainers/testcontainers-go vs ory/dockertest 書くことが少しふえるものの testcontainers-go だと事細かに設定できる
重い腰あげて移行するか〜 👴
30 testcontainers への移行 移行するのにどれくらいかかった? 2〜3日
31 testcontainers への移行 移行するのにどれくらいかかった? 2〜3日 そこまでプロダクトの規模が 大きくなかったのでサクッとおわった
32 testcontainers 使用箇所 プロジェクトとして使っている箇所 決裁 • API ◦ Cloud Spanner
CMS • API • Cloud Functions ◦ PostgreSQL (Cloud SQL)
サクッと移行できて 安定的に運用できているんで変えて良かった〜 🙌
まとめ 03
35 まとめ 課題は、まだたくさんある • 各テストケースごとに testcontainers を起動するためテスト実行時間がながい • コンテナの起動を並列化する チームへの浸透
• モックでいいじゃんってならないために必要性をきちんと解いていく testcontainers の利便性 • リリース頻度が活発 • ドキュメントが豊富 ◦ Docker 公式からもブログが出ている • テストケースごとにコンテナを起動する ◦ flaky なテストを回避しやすい
幸せなテストライフを!
Thank You
38 引用 • https://hasura.io/ • https://testcontainers.com/ • https://golang.testcontainers.org/ • https://github.com/ory/dockertest
• https://github.com/testcontainers/testcontainers-go • https://zenn.dev/shiguredo/articles/go-test-dockertest • https://zenn.dev/jy8752/articles/419ab77b2b6a61 • https://www.docker.com/ja-jp/blog/testcontainers-best-practices/