cargo test 默认会运行全部测试,包括:
-
单元测试(Unit tests)
-
内嵌在
src/lib.rs中的测试 -
内嵌在
src/main.rs中的测试(这个示例里没有)
-
-
集成测试(Integration tests)
-
tests/目录下的 所有.rs文件 都会被编译成独立的测试包并运行 -
你的项目里:
integration_full_flow.rs,unit_order_state.rs,unit_parser.rs,unit_sizer.rs,unit_ws_monitor.rs
-
-
文档测试(Doc tests)
-
代码注释中的
```rust示例代码块
-
如何控制测试范围?
| 命令 | 效果 |
|---|---|
cargo test | 运行全部测试 |
cargo test --lib | 只运行 src/lib.rs 中的单元测试 |
cargo test --bin <name> | 只运行指定二进制文件的测试 |
cargo test --test <filename> | 只运行 tests/ 目录下的某个文件(不含 .rs 后缀) |
cargo test <pattern> | 运行名称匹配模式的测试函数(支持模糊匹配) |
示例:
# 只运行 tests/unit_sizer.rs
cargo test --test unit_sizer
# 只运行名字包含 "parser" 的测试函数
cargo test parser
配置技巧
如果你的 tests/ 目录下有某些文件不想被自动运行(比如需要手动执行的基准测试或场景测试),可以在 Cargo.toml 中配置:
[[test]]
name = "manual_stress_test"
path = "tests/stress_test.rs"
autotest = false # 这个文件不会被 cargo test 自动运行
总结:你的输出完全符合预期,tests/ 目录下的每个 .rs 文件都被作为独立的集成测试套件运行了。
138

被折叠的 条评论
为什么被折叠?



