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
Sugar Sato
December 10, 2024
Programming
580
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
360
Bref でサービスを運用している話
sgash708
0
370
tool ディレクティブを導入してみた感想
sgash708
1
320
DeepWiki で Go をもっと好きになろう
sgash708
0
1.1k
環境変数ライブラリ選手権
sgash708
0
340
はじめての Go * WASM * OCR
sgash708
1
460
もう僕は OpenAPI を書きたくない
sgash708
6
2.8k
【懺悔】1年目 EM の失敗から学ぼう
sgash708
0
270
「僕ら」のテストに対する向き合い方
sgash708
5
570
Other Decks in Programming
See All in Programming
SODA - FACT BOOK(EN)
sodainc
1
210
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
150
Goコンパイラを作ってGoをもっと理解する / Build a Go compiler to better understand Go
ikura_hamu
0
120
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
220
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
300
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
3
1.7k
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
210
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
420
Spec-driven Development with AI
simas
PRO
0
2.3k
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
1.8k
AI Augmentation Techniques with Liberty
ivargrimstad
1
390
Performance Optimization With LLMs
xleitix
0
240
Featured
See All Featured
How to build a perfect <img>
jonoalderson
1
6.2k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.6k
Building an army of robots
kneath
307
47k
Discover your Explorer Soul
emna__ayadi
2
1.3k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
520
Statistics for Hackers
jakevdp
799
230k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
390
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
560
How to Ace a Technical Interview
jacobian
280
24k
Darren the Foodie - Storyboard
khoart
PRO
4
4.1k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
370
Making the Leap to Tech Lead
cromwellryan
135
10k
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/