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
Spring Boot と AWS S3 を使ったアプリケーションのテスト
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Daisuke Garaike
June 17, 2025
Programming
140
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
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
520
立川で超かぐや姫!について話したい / Talking Cosmic Princess Kaguya! in Tachikawa
contour_gara
1
330
AR グラス + ミニ PC で実現する新しいモバイル環境
contour_gara
0
330
TDD 実践ミニトーク
contour_gara
1
420
ノート PC に Linux 入れてみたけど結構良かった
contour_gara
0
3.5k
JUnit5 から Kotest へ
contour_gara
0
210
社外での学びを社内に還元したい
contour_gara
1
550
2 週間で Twitter Bot を作ってみた
contour_gara
0
1.3k
Database Rider を用いたデータベーステスト
contour_gara
0
480
Other Decks in Programming
See All in Programming
JavaDoc 再入門
nagise
0
320
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
230
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
1.9k
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
130
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
0
200
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
150
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
3.6k
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
530
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
130
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
320
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
210
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
210
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Prompt Engineering for Job Search
mfonobong
0
340
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
390
How to train your dragon (web standard)
notwaldorf
97
6.7k
What's in a price? How to price your products and services
michaelherold
247
13k
Code Reviewing Like a Champion
maltzj
528
40k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
470
Agile that works and the tools we love
rasmusluckow
331
21k
sira's awesome portfolio website redesign presentation
elsirapls
0
280
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
200
How GitHub (no longer) Works
holman
316
150k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
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