我正在学习编写生锈的单元测试。但是,当它们不在src/lib.rs
或src/main.rs
中时,我无法运行测试。
我创建了一个具有以下结构的项目:
├── Cargo.lock
├── Cargo.toml
├── src
├── lib.rs
└── main.rs
└── functions.rs
并添加以下代码:
main.rs
#[cfg(test)]
mod test {
#[test]
fn test_main() {}
}
lib.rs
#[cfg(test)]
mod test {
#[test]
fn test_lib() {}
}
functions.rs
#[cfg(test)]
mod test {
#[test]
fn test_functions() { }
}
当我运行cargo test
时,这就是我得到的:
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running target\debug\deps\rust_unittests-b0ed92af162e0288.exe
running 1 test
test test::test_lib ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Running target\debug\deps\rust_unittests-c4edac234e8e3d9a.exe
running 1 test
test test::test_main ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Doc-tests rust_unittests
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
main.rs和lib.rs中的测试功能按预期运行,但function.rs中的测试功能未按预期运行。
我阅读了Rust的书和我在Google上搜索过的几篇文章,但都没有提到这个问题。我想念什么?