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
Daisuke Garaike
June 17, 2025
Programming
150
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
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
420
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
650
立川で超かぐや姫!について話したい / Talking Cosmic Princess Kaguya! in Tachikawa
contour_gara
1
410
AR グラス + ミニ PC で実現する新しいモバイル環境
contour_gara
0
370
TDD 実践ミニトーク
contour_gara
1
430
ノート PC に Linux 入れてみたけど結構良かった
contour_gara
0
3.6k
JUnit5 から Kotest へ
contour_gara
0
220
社外での学びを社内に還元したい
contour_gara
1
580
2 週間で Twitter Bot を作ってみた
contour_gara
0
1.3k
Other Decks in Programming
See All in Programming
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.9k
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
140
Foundation Models frameworkで画像分析
ryodeveloper
1
600
React本体のコードリーディング
high_g_engineer
1
140
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
170
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
470
Built Our Own Background Agent at LayerX
layerx
PRO
9
5.2k
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
180
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
550
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
210
the container ship “Apple Silicon”@WWDC26 Recap -Japan-\(region).swift
shingangan
0
120
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
410
First, design no harm
axbom
PRO
2
1.2k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
520
The Limits of Empathy - UXLibs8
cassininazir
1
600
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
640
Rails Girls Zürich Keynote
gr2m
96
14k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.1k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
420
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
A better future with KSS
kneath
240
18k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.3k
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