Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
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
520
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
160
Bref でサービスを運用している話
sgash708
0
280
tool ディレクティブを導入してみた感想
sgash708
1
280
DeepWiki で Go をもっと好きになろう
sgash708
0
1k
環境変数ライブラリ選手権
sgash708
0
280
はじめての Go * WASM * OCR
sgash708
1
410
もう僕は OpenAPI を書きたくない
sgash708
6
2.6k
【懺悔】1年目 EM の失敗から学ぼう
sgash708
0
240
「僕ら」のテストに対する向き合い方
sgash708
5
540
Other Decks in Programming
See All in Programming
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.6k
OSもどきOS
arkw
0
560
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
330
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
5.8k
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
470
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
130
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
750
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
160
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
120
Oxcを導入して開発体験が向上した話
yug1224
4
310
Contextとはなにか
chiroruxx
1
320
スマートグラスで並列バイブコーディング
hyshu
0
140
Featured
See All Featured
Faster Mobile Websites
deanohume
310
31k
Code Review Best Practice
trishagee
74
20k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
KATA
mclloyd
PRO
35
15k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
The Pragmatic Product Professional
lauravandoore
37
7.3k
Building the Perfect Custom Keyboard
takai
2
790
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
330
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Optimising Largest Contentful Paint
csswizardry
37
3.7k
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/