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
Satoshi SAKAO
November 20, 2024
Programming
0
56
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
83
JavaScriptのデバッグ/2023-09-04-llt30
ottijp
0
150
CDK for TerraformでAzureリソースをデプロイする/2023-05-15-llt29
ottijp
1
270
TWELITEへの誘い/2022-12-27-llt28
ottijp
0
150
ビルドツールBazelを触ってみた/2022-09-28-llt27
ottijp
0
160
HashiCorp Vaultを使ったシークレットのセキュアな一元管理 〜Ansibleを添えて〜/2022-07-12-llt26
ottijp
0
150
AWSインフラのデプロイをCDKでカイゼンする/2022-03-23-llt25
ottijp
0
87
Amazon Timestreamでデータ補間/2021-12-27-llt24
ottijp
0
100
ncurses/2021-05-12-llt21
ottijp
0
210
Other Decks in Programming
See All in Programming
The Niche of CDK Grant オブジェクトって何者?/the-niche-of-cdk-what-isgrant-object
hassaku63
1
720
プロダクトという一杯を作る - プロダクトチームが味の責任を持つまでの煮込み奮闘記
hiliteeternal
0
290
AWS Summit Japan 2024と2025の比較/はじめてのKiro、今あなたは岐路に立つ
satoshi256kbyte
1
250
AIに安心して任せるためにTypeScriptで一意な型を作ろう
arfes0e2b3c
0
270
構文解析器入門
ydah
7
1.9k
AI コーディングエージェントの時代へ:JetBrains が描く開発の未来
masaruhr
2
220
オンコール⼊⾨〜ページャーが鳴る前に、あなたが備えられること〜 / Before The Pager Rings
yktakaha4
2
1.2k
知って得する@cloudflare_vite-pluginのあれこれ
chimame
1
120
テスターからテストエンジニアへ ~新米テストエンジニアが歩んだ9ヶ月振り返り~
non0113
2
240
脱Riverpod?fqueryで考える、TanStack Queryライクなアーキテクチャの可能性
ostk0069
0
570
Gemini CLI のはじめ方
ttnyt8701
1
110
中級グラフィックス入門~効率的なメッシュレット描画~
projectasura
3
1.7k
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
GraphQLとの向き合い方2022年版
quramy
49
14k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
Docker and Python
trallard
45
3.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.8k
Done Done
chrislema
184
16k
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