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
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
880
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
160
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.6k
VibeCodingからAgenticWorkflowへ
starfish719
0
360
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
2.8k
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.4k
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
18k
What's New in Android 2026
veronikapj
0
260
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
今さら聞けない .NET CLI
htkym
0
190
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
150
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
150
Featured
See All Featured
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
680
エンジニアに許された特別な時間の終わり
watany
108
250k
Design in an AI World
tapps
1
280
Believing is Seeing
oripsolob
1
180
Building the Perfect Custom Keyboard
takai
2
840
First, design no harm
axbom
PRO
2
1.2k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
How GitHub (no longer) Works
holman
316
150k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
410
Test your architecture with Archunit
thirion
1
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