单元测试
Rust 和 Cargo 随附了一个简单的单元测试框架:
-
单元测试在您的整个代码中都受支持。
-
您可以通过
tests/
目录来支持集成测试。
Tests are marked with #[test]
. Unit tests are often put in a nested tests
module, using #[cfg(test)]
to conditionally compile them only when building tests.
- 这样一来,您可以对专用帮助程序进行单元测试。
- 仅当您运行
cargo test
时,#[cfg(test)]
属性才有效。
Speaker Notes
This slide should take about 5 minutes.
在 Playground 中运行测试显示测试结果。