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
910
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
760
立川で超かぐや姫!について話したい / Talking Cosmic Princess Kaguya! in Tachikawa
contour_gara
1
490
AR グラス + ミニ PC で実現する新しいモバイル環境
contour_gara
0
410
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
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2.2k
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
180
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
130
Agents on Rails - Rails at Scale 2026
irinanazarova
0
330
プロダクトコードからライブラリの境界を見つける
elmetal
PRO
0
100
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1.1k
Workers Cache を知る
syumai
0
330
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
230
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
230
Heart of Swift Concurrency
koher
0
1.2k
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
13
6.5k
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
160
Featured
See All Featured
KATA
mclloyd
PRO
35
16k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
910
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
310
Automating Front-end Workflow
addyosmani
1369
210k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Writing Fast Ruby
sferik
630
63k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Balancing Empowerment & Direction
lara
6
1.3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
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