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.5k
our test strategy on actix-web app
Kentaro Matsumoto
May 19, 2022
Tweet
Share
More Decks by Kentaro Matsumoto
See All by Kentaro Matsumoto
Marpを使って登壇資料を作る
matsu7874
0
610
Generate a rust client code by OpenAPI Generator
matsu7874
0
350
ざっと理解するRust 2024 Edition
matsu7874
0
920
プリントデバッグを失敗させないテクニック
matsu7874
1
330
社外を巻き込んだ勉強会を定期開催するコツ
matsu7874
0
170
actix-webを使った開発のハマリポイントを避けたい
matsu7874
0
1k
roadmap to rust 2024
matsu7874
0
2k
Rust tutorial for Pythonista
matsu7874
2
1.2k
Mock testing with mockall
matsu7874
0
350
Other Decks in Programming
See All in Programming
5分で理解する SOLID 原則 #phpcon_nagoya
shogogg
1
280
Datadog Workflow Automation で圧倒的価値提供
showwin
1
100
Java Webフレームワークの現状 / java web framework at burikaigi
kishida
9
2.2k
Django NinjaによるAPI開発の効率化とリプレースの実践
kashewnuts
1
200
CDK開発におけるコーディング規約の運用
yamanashi_ren01
2
220
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
880
2025.2.14_Developers Summit 2025_登壇資料
0101unite
0
130
PHP ステートレス VS ステートフル 状態管理と並行性 / php-stateless-stateful
ytake
0
110
Code smarter, not harder - How AI Coding Tools Boost Your Productivity | Angular Meetup Berlin
danielsogl
0
100
ソフトウェアエンジニアの成長
masuda220
PRO
12
2k
GoとPHPのインターフェイスの違い
shimabox
2
200
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
140
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
22
1.4k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
250
4 Signs Your Business is Dying
shpigford
182
22k
What's in a price? How to price your products and services
michaelherold
244
12k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
52k
For a Future-Friendly Web
brad_frost
176
9.6k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Embracing the Ebb and Flow
colly
84
4.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.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しましょう↓