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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Kentaro Matsumoto
May 19, 2022
Programming
1.7k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
740
ざっと理解するRust 2024 Edition
matsu7874
0
1.9k
プリントデバッグを失敗させないテクニック
matsu7874
1
480
社外を巻き込んだ勉強会を定期開催するコツ
matsu7874
0
240
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
Contextとはなにか
chiroruxx
1
330
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
180
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
360
OSもどきOS
arkw
0
570
Oxcを導入して開発体験が向上した話
yug1224
4
320
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
6
1.3k
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
660
AI 輔助遺留系統現代化的經驗分享
jame2408
1
740
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.7k
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
150
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
550
Featured
See All Featured
Designing for Timeless Needs
cassininazir
1
260
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Code Review Best Practice
trishagee
74
20k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Writing Fast Ruby
sferik
630
63k
Between Models and Reality
mayunak
4
340
Navigating Weather and Climate Data
rabernat
0
220
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Paper Plane
katiecoart
PRO
1
51k
Producing Creativity
orderedlist
PRO
348
40k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
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しましょう↓