如题最近在学习 Rust
然后尝试在 test
目录的测试文件中使用 main
文件里定义的函数但是报错:
error[E0433]: failed to resolve: there are too many leading `super` keywords
--> tests\integration_test.rs:1:5
|
1 | use super::*;
| ^^^^^ there are too many leading `super` keywords
求教能这么操作么?还是一定要放到 lib
目录里然后搞个模块:(代码如下)
main.rs
fn main() {
}
fn scope_test() -> i32 {
return 100;
}
tests/test_a.rs
use super::*;
#[test]
fn test_a() {
println!("A");
assert_eq!(scope_test(), 100);
}
1. 可以在main.rs 写测试
2. 把main.rs引入到tests下的 test_a mod 中进行测试
下面要注意的是 tests/test_a mod 的位置 以及 tests是在src下;
Codes in src/tests/mod.rs
Codes in src/tests/test_a.rs
Codes in src/mian.rs 注意 fn_in_main 声明为
pub
3. 引入lib.rs 还在src/tests/test_a 进行测试
Codes in main.rs
Codes in lib.rs
Codes in tests/mod.rs
Codes in tests/test_a.rs;
Refs
packages-and-crates