Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
our test strategy on actix-web app
Search
Kentaro Matsumoto
May 19, 2022
Programming
0
1.6k
our test strategy on actix-web app
Kentaro Matsumoto
May 19, 2022
Tweet
Share
More Decks by Kentaro Matsumoto
See All by Kentaro Matsumoto
claude_code.pdf
matsu7874
5
7.2k
Marpを使って登壇資料を作る
matsu7874
0
1.8k
Generate a rust client code by OpenAPI Generator
matsu7874
0
610
ざっと理解するRust 2024 Edition
matsu7874
0
1.7k
プリントデバッグを失敗させないテクニック
matsu7874
1
420
社外を巻き込んだ勉強会を定期開催するコツ
matsu7874
0
210
actix-webを使った開発のハマリポイントを避けたい
matsu7874
0
1.1k
roadmap to rust 2024
matsu7874
0
2.1k
Rust tutorial for Pythonista
matsu7874
2
1.4k
Other Decks in Programming
See All in Programming
The Art of Re-Architecture - Droidcon India 2025
siddroid
0
130
モデル駆動設計をやってみようワークショップ開催報告(Modeling Forum2025) / model driven design workshop report
haru860
0
280
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
3
1.3k
マスタデータ問題、マイクロサービスでどう解くか
kts
0
130
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
8
3.3k
Implementation Patterns
denyspoltorak
0
120
gunshi
kazupon
1
120
Claude Codeの「Compacting Conversation」を体感50%減! CLAUDE.md + 8 Skills で挑むコンテキスト管理術
kmurahama
1
640
AIコーディングエージェント(NotebookLM)
kondai24
0
230
Developing static sites with Ruby
okuramasafumi
0
330
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
120
JETLS.jl ─ A New Language Server for Julia
abap34
2
460
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
4.9k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
New Earth Scene 8
popppiees
0
1.2k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
57
39k
How to train your dragon (web standard)
notwaldorf
97
6.4k
Documentation Writing (for coders)
carmenintech
77
5.2k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
310
How Software Deployment tools have changed in the past 20 years
geshan
0
30k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
51
45k
The Cult of Friendly URLs
andyhume
79
6.7k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.2k
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しましょう↓