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
Kentaro Matsumoto
May 19, 2022
Programming
0
1.7k
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.4k
Marpを使って登壇資料を作る
matsu7874
0
2.1k
Generate a rust client code by OpenAPI Generator
matsu7874
0
670
ざっと理解するRust 2024 Edition
matsu7874
0
1.8k
プリントデバッグを失敗させないテクニック
matsu7874
1
450
社外を巻き込んだ勉強会を定期開催するコツ
matsu7874
0
220
actix-webを使った開発のハマリポイントを避けたい
matsu7874
0
1.2k
roadmap to rust 2024
matsu7874
0
2.2k
Rust tutorial for Pythonista
matsu7874
2
1.4k
Other Decks in Programming
See All in Programming
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
320
CSC307 Lecture 15
javiergs
PRO
0
230
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
410
Rで始めるML・LLM活用入門
wakamatsu_takumu
0
170
エンジニアの「手元の自動化」を加速するn8n 2026.02.27
symy2co
0
110
API Platformを活用したPHPによる本格的なWeb API開発 / api-platform-book-intro
ttskch
1
130
あなたはユーザーではない #PdENight
kajitack
4
340
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
9
2.6k
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
490
Event Storming
hschwentner
3
1.3k
grapheme_strrev関数が採択されました(あと雑感)
youkidearitai
PRO
1
210
2026年は Rust 置き換えが流行る! / 20260220-niigata-5min-tech
girigiribauer
0
230
Featured
See All Featured
The Language of Interfaces
destraynor
162
26k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
960
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
HDC tutorial
michielstock
1
510
Making Projects Easy
brettharned
120
6.6k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
How to make the Groovebox
asonas
2
2k
Agile that works and the tools we love
rasmusluckow
331
21k
Mobile First: as difficult as doing things right
swwweet
225
10k
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しましょう↓