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
DBを使ったテストで詰まった点とその対策
Search
sontixyou
September 11, 2024
570
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
DBを使ったテストで詰まった点とその対策
Rustを使ったWebアプリケーションでのDBを用いたテストに関する発表です
sontixyou
September 11, 2024
More Decks by sontixyou
See All by sontixyou
SkillがSkillを生む:QA観点出しを自動化した
sontixyou
7
4.3k
Claude Codeと駆け抜ける 情報収集と実践録
sontixyou
2
2.1k
開発メンバーが語るFindy Conferenceの裏側とこれから
sontixyou
2
1.8k
Featured
See All Featured
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
740
Un-Boring Meetings
codingconduct
0
430
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
A Modern Web Designer's Workflow
chriscoyier
699
190k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
330
My Coaching Mixtape
mlcsv
0
320
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
The Language of Interfaces
destraynor
162
27k
Mind Mapping
helmedeiros
1
370
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Transcript
2024/09/11 RustのWebアプリ開発 LT道場 〜テスト編〜 DBを使ったテストで詰まった点とその対策 01 1
02 2 西村 憲悟 [にしむら けんご] ファインディ株式会社 / バックエンド @sontixyou
• Webアプリケーションのテストで直面した課題 • 問題に対しての解決アプローチ • まとめ 今日話すこと 03 3
今日話さないこと 04 • テストデータの作成を楽にする方法 • どこの月見バーガーがうまいのか 4
• 実行を短時間で終わらせたい • テストケース間で干渉しないようにテス トしたい テストに対してのモチベーション 05 5
アプリケーションの構成 06 6 アプリケーション DB ORM: sea-orm https://github.com/SeaQL/sea-orm
アプリケーションコード 07 7 DBコネクションしてから postテーブルにレコードを作成 DBコネクションしてから
postテーブルにあるレコードを更新
テストコード 08 8
各テストがひとつのDBを使う状態で cargo testするとどうなるのか? テストの問題点 09 9
• 複数のテストが同じDBにデータを読み書きすると、 テスト同士で影響が出る ◦ テストが失敗したり、flakyになる テストの問題点 10 10
ユニーク制約ぐぬぬ DBのユニーク制約にひっかかり、自分が作りたいデータ を作成できない テストの問題点 11 11
• △ 実行を短時間で終わらせたい • ✗ テストケース間で干渉する テストの問題点 12 12
cargo testをすると並列でテストが実行されるため https://doc.rust-lang.org/book/ch11-02-running-tests.html#running-tests-in-parallel-or-consecutively DBへCRUDする場合での難しさ 13 13
• テストケースごとにDBを分ける • 並列数を1にする ◦ cargo testのオプションで可能 • モックDBを使う ◦
sea-ormでサポートされている 対応方法候補 14 14
• テストケースごとにDBを分ける • 並列数を1にする • モックDBを使う 対応方法候補 15 15
テスト実行前にDBを作成。 実行後にDBを削除する。 ↓ test_contextを使用することで実現可能になる。 https://docs.rs/test-context/latest/test_context/ テストケースごとにDBを分ける 準備編 16 16
テストケースごとにDBを分ける 実装編 17 17
テストケースごとにDBを分ける 実装編 18 18 setupとteardown関数を呼び出す下準備
テストケースごとにDBを分ける 実装編 19 19 テストに対してのモチベーション • ✅ テスト実行を短時間で終わる • ✅ テストケース間で干渉しない
テストケースごとにDBを分ける 実装編 20 20 実装の詳細はこちらを見てほしい🦀 https://github.com/sontixyou/sea_orm_practice_db2024
まとめ 21 21 • 並列でテスト実行をするときはDBの接続先に気 をつけよう • sea-ormを使う際は一工夫が必要 ◦ 自前実装が手間ならsqlxを使うのも手
宣伝 開催日時: 10月 8日 (火曜日) 19:30~ ↓詳細はこちら↓ 22 22 🦀Rust地域コミュニティ🦀
Osaki.rs はじめました!!