我想建立一个基本的 hello world 项目。单元测试应该在书中test/
描述的目录中。到目前为止,我的代码如下。
src/main.rs
pub mod player;
fn main() {
println!("Hello, world!");
}
src/player.rs
pub fn rep(arg: i32) -> i32 {
arg
}
测试/player.rs
extern crate player;
#[test]
fn it_works() {
assert_eq!(4, player::rep(2+2));
}
货运.toml
[package]
name = "myapp"
version = "0.1.0"
authors = ["My Name <spam@example.com>"]
我相信代码与书中非常相似。但是,cargo test
失败:
tests/player.rs:1:1: 1:21 error: can't find crate for `player`
tests/player.rs:1 extern crate player;
^~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
问题是什么?我完全迷路了。