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
Spring Boot と AWS S3 を使ったアプリケーションのテスト
Search
Daisuke Garaike
June 17, 2025
Programming
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Spring Boot と AWS S3 を使ったアプリケーションのテスト
Daisuke Garaike
June 17, 2025
More Decks by Daisuke Garaike
See All by Daisuke Garaike
Go を使い始めて 2 ヶ月の学び / My first two months with Go
contour_gara
0
440
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
930
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
780
立川で超かぐや姫!について話したい / Talking Cosmic Princess Kaguya! in Tachikawa
contour_gara
1
500
AR グラス + ミニ PC で実現する新しいモバイル環境
contour_gara
0
420
TDD 実践ミニトーク
contour_gara
1
440
ノート PC に Linux 入れてみたけど結構良かった
contour_gara
0
3.7k
JUnit5 から Kotest へ
contour_gara
0
220
社外での学びを社内に還元したい
contour_gara
1
610
Other Decks in Programming
See All in Programming
sbt 2.0: takeoff
eed3si9n
0
150
最近”作らせてる” ローカルAIアプリの話
akit37
0
460
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
260
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
1
130
ジョジョの世界をXRで再現する
mofurune
0
160
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
SREの越境 / SRE Collaboration
y0hgi
2
310
JRuby: Past, Present, and Future
headius
0
230
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
480
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
490
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
470
Featured
See All Featured
Designing Powerful Visuals for Engaging Learning
tmiket
1
600
Abbi's Birthday
coloredviolet
4
10k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
We Have a Design System, Now What?
morganepeng
55
8.4k
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
So, you think you're a good person
axbom
PRO
2
2.2k
Designing for Performance
lara
612
70k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.3k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
260
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
740
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Transcript
Spring Boot と AWS S3 を使った アプリケーションのテスト 2025-06-06 JJUG CCC
2025 Spring Daisuke Garaike
自己紹介 gara Twitter: @contour_gara Java で百貨店システムの開発 アジャイルでテストを知る テストがないコードがつらくて、 どうテストを書くかばかり考えている 2
JJUG CCC 登壇は 2 回目 3
S3 を使ったアプリケーション - バックエンド用途で考える - データ連携のためのデータストア - メッセージングで異常があった 際の退避場所 -
画像の保存 - etc. 4
目的 - モダンな Web アプリケーション で使われる S3 - そんな S3
を使うアプリケーション のテストを書くモチベーションが 上がる 5
テストは必要なのか 6
テストは書きたい - 変更に強い - ソースコードの変更 - ライブラリアップデート - AWS SDK:
ほぼ毎日 - 書いたコードが正確に動くこと を確信できる 7
何をテストするべきか - ソフトウェアの振る舞い - 入力 - 出力 - 保存 -
計算 - リポジトリクラスは 3 つの 振る舞いあり - 入力・出力・保存 8
問題を整理 9
S3 を使うクラスのテストの必要性は? - 堅牢なコードのほとんどはエラーハンドリング 10 public String createDownloadUrl(String bucket, String
key) { if (bucketIsNotPresent(bucket)) throw new RuntimeException("バケットが存在しません。"); if (objectIsNotPresent(bucket, key)) throw new RuntimeException("オブジェクトが存在しません。"); return s3Presigner .presignGetObject( getObjectPresignRequest -> getObjectPresignRequest .getObjectRequest(getObjectRequest -> getObjectRequest.bucket(bucket).key(key)) .signatureDuration(Duration.ofMinutes(10)) ) .url() .toExternalForm(); }
技術的な課題 - ドメイン・リポジトリはともに アプリケーションの端 - 違い: - ドメイン: 純粋関数 -
リポジトリ: さらに外に 外部サービス 11
技術的な課題 - ドメイン・リポジトリはともに アプリケーションの端 - 違い: - ドメイン: 純粋関数 -
リポジトリ: さらに外に 外部サービス 12 Presentation UseCase DB・S3 Domain Infra
テストダブル - ダミー・スタブ・スパイ・モック - インターフェースに もどづきふるまう - フェイク - 外部サービスとして
ふるまう - テスト機構なし 13 モック スパイ スタブ ダミー フェイク テストダブル
LocalStack - AWS のサービスを docker 上で再現 14
テスト戦略 15
テストピラミッド - UT と IT 区別 - レイヤーをまたぐかどうか 16 出典:
https://gihyo.jp/dev/serial/01/savanna-letter/0005
テストスコープ - Large: S3 - Medium: LocalStack 17 Small Medium
Large
結局、何をどうテストするのか - LocalStack を使う UT はコスパが悪い - 結合すると、データ準備の コストが増す -
UT x Medium: 基本 - IT x Medium: ハッピーパス, etc. 18 Small Medium Large Unit Integra tion E2E
demo 19
リポジトリ 20 - https://github.com/contour-gara/spring-s3-sample-jjug-ccc-2025
システム構成 21
作成した API 22 - 全件検索 - 画像をダウンロードするための署名付き URL 作成 -
保存 - 画像をアップロードするための署名付き URL 作成
AwsConfig 23 - AWS のクレデンシャルなどは アプリのプロパティにする ことでテストしやすくなる
UT 24
Testcontainers 25 - イメージ選定 - プロパティ設定
endpointOverride 26 - LocalStack に向けるため - プロパティが空文字かどうか で使い分けられるとスマート
データ準備と後処理 27 - 後処理: テストケース実行前に - 共通処理 - 準備は後処理の後 -
各テスト毎
IT 28
アプリケーションコンテナに対するテスト 29
forcePathStyle 30 - http://localstack:4566/ をエンドポイントとして 使うため
maven-failsafe-plugin 31 - 結合テストを実行するため
docker-compose-maven-plugin 32 - pre-integration-test で compose up - post-integration-test で
compose down - verify で up -> IT -> down
まとめ 33
感謝 34 - S3 を使用するクラスは、LocalStack を使って 自動テストが書ける - UT: Testcontainers,
LocalStack に 切り替えられる実装 - IT: docker-compose-maven-plugin などの plugin