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
our test strategy on actix-web app
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kentaro Matsumoto
May 19, 2022
Programming
1.7k
0
Share
our test strategy on actix-web app
Kentaro Matsumoto
May 19, 2022
More Decks by Kentaro Matsumoto
See All by Kentaro Matsumoto
claude_code.pdf
matsu7874
5
7.6k
Marpを使って登壇資料を作る
matsu7874
0
2.3k
Generate a rust client code by OpenAPI Generator
matsu7874
0
720
ざっと理解するRust 2024 Edition
matsu7874
0
1.8k
プリントデバッグを失敗させないテクニック
matsu7874
1
480
社外を巻き込んだ勉強会を定期開催するコツ
matsu7874
0
230
actix-webを使った開発のハマリポイントを避けたい
matsu7874
0
1.2k
roadmap to rust 2024
matsu7874
0
2.2k
Rust tutorial for Pythonista
matsu7874
2
1.5k
Other Decks in Programming
See All in Programming
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
6
760
Talking to terminals (and how they talk back) (KotlinConf 2026)
jakewharton
PRO
1
160
LLM Plugin for Node-REDの利用方法と開発について
404background
0
140
inferと仲良くなる10分間
ryokatsuse
1
280
次世代リンターで探る、tsgo 時代における型認識カスタムルールの現実解
ytakahashii
3
1.3k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3k
RTSPクライアントを自作してみた話
simotin13
0
380
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
500
tsserverとは何だったのか、これからどうなるのか
nowaki28
1
420
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
140
OSもどきOS
arkw
0
350
RailsTokyo 2026#4: AI様があれば、 Hotwireの弱点は消えるか?
naofumi
5
1k
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.8k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
150
A Soul's Torment
seathinner
6
2.9k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
580
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
The Pragmatic Product Professional
lauravandoore
37
7.3k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
230
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
Transcript
actix-webのテストどうしてる? @matsu7874
matsu7874 • @matsu7874 • SWE@estie • オフィス不動産領域のSaaS • 新しいプロダクトをRustで開発しています •
『実践Rustプログラミング入門』共著 • TechFeed Official Expert(Rust)
3 モジュール構成と役割 Main Webサーバの起動 ルーティングの設定 Api ユースケースごとに必要 な処理を行う Sql サブクレート
DBに問い合わせを行う MySQL 矢印は呼び出しの方向
4 モジュール構成とテスト Main Webサーバの起動 ルーティングの設定 Api ユースケースごとに必要 な処理を行う Sql サブクレート
DBに問い合わせを行う MySQL 単体テスト ドメインロジックだけ 結合テスト アプリケーションをテストDBに接続してAPIを実行する `cargo test cargo test -- --test-threads=1 --ignored `で実行 単体テスト ドメインロジックだけ
テスト実行の実行方法 actix-webというフレームワークを使っています。 実行方法は変わりません、書き方がすこし変わります。 • `cargo test –workspace`: workspace全体のテストが実行できます • `cd
sql; cargo test` とsqlクレートを個別にテストする必要はありません。 • 結合テストは `cargo test --ignore` で実行できます
6 モジュール構成とテスト(再掲) Main Webサーバの起動 ルーティングの設定 Api ユースケースごとに必要 な処理を行う Sql サブクレート
DBに問い合わせを行う MySQL 単体テスト ドメインロジックだけ 結合テスト アプリケーションをテストDBに接続してAPIを実行する `cargo test cargo test -- --test-threads=1 --ignored `で実行 単体テスト ドメインロジックだけ
単体テストの実装 src/api/building.rsとかに実装 • 普通に単体テストを実装 • #[test]というアトリビュートをつけて実装のあるファイルに書く • ビジネスロジック, From<型>のテストを実装する
結合テストの実装 tests/test_api_building.rs #[test]の代わりに#[actix_web::test]をつける mysqlはモックしない
結合テストの実装 tests/test_api_hoge.rs auth0のモック サービスを起動 リクエストを作って レスポンスを得る
今後重要度が上る可能性のある問題 何か解決策を思いついた方はぜひコメントで教えてください。 • 結合テストを並列で実行できていない • 利用するデータをきれいに分けられれば良さそう • SQLが正しいことをテストできてない • MySQLもモックして、Rust側で問題ないことを担保する?
actix-webを使った結合テストも簡単に書ける!
感想など • middlewareを使っていても全部モックしなくても良さそう • こまめに境界で型を作っていくとびっくりが少なくて良かった Rustでの開発についてもっと聞きたいぜという方、meetyしましょう↓