项目结构

执行命令 tree .
项目结构如下 (tests 包 与 src 同级, 用于存放测试代码)
image.png

分模块测试

image.png

  • 测试所有#[test] 属性方法

cargo test

  • 只测试thread 文件下的 标识有#[test] 属性的方法 (— —nocapture 标识 打印输出

cargo test —test thread — —nocapture

  • 只测试thread 文件下 的 test1 方法

cargo test —test thread test1

参考

https://doc.rust-lang.org/book/ch11-03-test-organization.html