單元測試
Rust 和 Cargo 提供了一個簡單的單元測試 (unit test) 框架:
-
在你的程式碼的任何地方都可添加單元測試。
-
整合測試 (integration test) 則可放置在
tests/
資料夾下。
測試會以 #[test]
標示。單元測試通常會位於巢狀的 tests
模組中,使用 #[cfg(test)]
可有條件地編譯測試 (僅限在建構測試時)。
- 這有助於您對私人輔助程式進行單元測試。
- 只有在執行
cargo test
時,#[cfg(test)]
屬性才會生效。
Speaker Notes
This slide should take about 5 minutes.
請在 Playground 中執行測試以顯示結果。