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/2024-11-20-llt32
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Satoshi SAKAO
November 20, 2024
Programming
0
83
Testcontainers/2024-11-20-llt32
社内のLTイベント「えるLT Vol.32 オンライン」で発表した資料です
Satoshi SAKAO
November 20, 2024
Tweet
Share
More Decks by Satoshi SAKAO
See All by Satoshi SAKAO
Pkl/2024-04-17-llt31
ottijp
0
110
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
180
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
310
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
180
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
200
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
170
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
120
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
120
ncurses/2021-05-12-llt21
ottijp
0
230
Other Decks in Programming
See All in Programming
生成 AI 時代のスナップショットテストってやつを見せてあげますよ(α版)
ojun9
0
310
20260320登壇資料
pharct
0
130
PHP 7.4でもOpenTelemetryゼロコード計装がしたい! / PHPerKaigi 2026
arthur1
1
440
守る「だけ」の優しいEMを抜けて、 事業とチームを両方見る視点を身につけた話
maroon8021
3
1.6k
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.4k
今からFlash開発できるわけないじゃん、ムリムリ! (※ムリじゃなかった!?)
arkw
0
160
AIコードレビューの導入・運用と AI駆動開発における「AI4QA」の取り組みについて
hagevvashi
0
570
AI 開発合宿を通して得た学び
niftycorp
PRO
0
180
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
410
車輪の再発明をしよう!PHP で実装して学ぶ、Web サーバーの仕組みと HTTP の正体
h1r0
2
440
Understanding Apache Lucene - More than just full-text search
spinscale
0
140
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
130
Featured
See All Featured
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
Six Lessons from altMBA
skipperchong
29
4.2k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
140
Building Adaptive Systems
keathley
44
3k
Paper Plane
katiecoart
PRO
0
48k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
430
A Modern Web Designer's Workflow
chriscoyier
698
190k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
120
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
490
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.1k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
350
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.7k
Transcript
Testcontainers Satoshi SAKAO えるLT Vol.32 2024-11-20  1
話すひと 2 🏢 インフォコム株式会社 サービスマネジメント室 👨🔧 ソフトウェアエンジニア 🛠 Node.js /
AWS / IoT / iOS (Swift) / Linux 💖 猫,B'z,テクテクライフ(ランク: 30),数学 Satoshi SAKAO @ottijp.com 𝕏 @ottijp
Now playing... 3 https://bsky.app/pro fi le/ottijp.com/post/3l7slr7xewc2z
Motivation 4 https://www.thoughtworks.com/radar/languages-and-frameworks/summary/testcontainers
Motivation 5 https://www.thoughtworks.com/radar/languages-and-frameworks/summary/pkl
Testcontainers • テストコードでDockerコンテナを起動し, "本物"を使ったintegration testを実現するライブラリ • コンテナで動かせるならなんでも(DB,MQ,ブラウザ,etc) • 自前でテスト実行前にコンテナ作ることもできるが, よりinstant
& disposableにコンテナを使える • AtomicJar社が開発.2023年12月にDockerが買収. 6
E ff ect 7 https://speakerdeck.com/twada/automated-test-knowledge-from-savanna-202406- fi ndy-dev-prod-con-edition?slide=30
E ff ect 8 https://speakerdeck.com/twada/automated-test-knowledge-from-savanna-202406- fi ndy-dev-prod-con-edition?slide=32
Example 9 import { expect } from 'chai' import {
GenericContainer } from 'testcontainers' import redis from 'async-redis' it('redis works', async () => { const container = await new GenericContainer('redis') .withExposedPorts(6379) .start() const client = redis.createClient( container.getFirstMappedPort(), container.getHost() ) await client.set('key', 'value') expect(await client.get('key')).to.equal('value') await client.quit() await container.stop() }) redisコンテナの作成 reidsクライアントの作成と テストデータのセット テストデータの検証 クリーンアップ
Features • テスト間でコンテナを再利用する • 実行中コンテナでコマンドを実行する • コンテナのログストリームを取得する • ネットワークを作成しコンテナへアタッチする •
イメージをビルドする • composeを起動する • ホストのポートをコンテナにexposeする • コンテナ起動とテストを同期する(Wait strategy) 10
Others • modules • 特定のタスクを行いやすくするためのユーティリティ • Testcontainers Cloud • Dockerランタイムを提供
• Testcontainers Desktop • コンテナのデバッグ,ポートフォワード 11
Supported runtimes • Docker • Podman • Colima • Rancher
Desktop 12 export DOCKER_HOST=unix://${HOME}/.rd/docker.sock export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
所感 • テストでコンテナをとても簡単に,信頼性高く利用できる • 環境構築やファイルシステムをいじるプログラムなどの テストとも相性が良さそう • Rancher Desktop対応が助かる 13
14 Appendix
Supported languages • Java • Go • .Net • Node.js
• Python • Rust • Haskell • Ruby 15
Wait strategy • ポートのリスン待ち(デフォルト) • Timeout • ログの出力待ち • Health
Check • httpレスポンス • コマンド実行結果 • カスタムストラテジ • またはこれらの組み合わせ 16
Refs • 公式ページ https://testcontainers.com/ 17