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
570
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
340
Bref でサービスを運用している話
sgash708
0
350
tool ディレクティブを導入してみた感想
sgash708
1
300
DeepWiki で Go をもっと好きになろう
sgash708
0
1.1k
環境変数ライブラリ選手権
sgash708
0
320
はじめての Go * WASM * OCR
sgash708
1
450
もう僕は OpenAPI を書きたくない
sgash708
6
2.8k
【懺悔】1年目 EM の失敗から学ぼう
sgash708
0
260
「僕ら」のテストに対する向き合い方
sgash708
5
560
Other Decks in Programming
See All in Programming
golang-bob.pdf
iwatsukayura
0
130
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
170
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
120
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
920
contenteditable と日本語入力に向き合う
colorful12
0
210
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
290
phperだってパンチカードでコーディングしたい
o0h
PRO
0
370
パスワード再設定メールのURLについて知っておこう
uyuki234
0
170
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
190
Seven New Principles of Software Engineering
yegor256
0
150
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
1k
Verilogで学ぶCPU自作入門
uyuki234
8
4.2k
Featured
See All Featured
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
290
Building Applications with DynamoDB
mza
96
7.2k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
330
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
450
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
310
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
Documentation Writing (for coders)
carmenintech
77
5.6k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
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/