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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Satoshi SAKAO
November 20, 2024
Programming
93
0
Share
Testcontainers/2024-11-20-llt32
社内のLTイベント「えるLT Vol.32 オンライン」で発表した資料です
Satoshi SAKAO
November 20, 2024
More Decks by Satoshi SAKAO
See All by Satoshi SAKAO
Pkl/2024-04-17-llt31
ottijp
0
130
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
190
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
330
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
190
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
220
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
180
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
240
Other Decks in Programming
See All in Programming
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
6
800
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
240
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
160
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
440
SPMマルチモジュールで テストカバレッジを取得する技法
yosshi4486
0
140
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
340
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
2k
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
130
LLM Plugin for Node-REDの利用方法と開発について
404background
0
160
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
1
710
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
270
Oxcを導入して開発体験が向上した話
yug1224
4
280
Featured
See All Featured
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Tell your own story through comics
letsgokoyo
1
940
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
230
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
830
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
Designing Experiences People Love
moore
143
24k
Why Our Code Smells
bkeepers
PRO
340
58k
Building Applications with DynamoDB
mza
96
7.1k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
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