我有以下生锈项目的布局:
project_name
├── crate_1
│ ├── src
│ │ ...
│ │ └── main.rs
│ └── Cargo.toml
├── crate_2
│ ├── src
│ │ ...
│ │ └── lib.rs
│ └── Cargo.toml
├── tests
│ └── tests.rs <-- run tests in here
└── Cargo.toml
我想使用cargo在tests
目录中运行这些测试,但是cargo似乎找不到它们。有办法让货物运过来吗?
发布于 2022-03-13 13:46:07
托基奥是一个很好的例子。
现在您已经有了一个tests
目录,让我们将其添加到工作区Cargo.toml
中的members
中。
[workspace]
members = [
"crate1",
"crate2",
"tests"
]
我们假设在test_crate1.rs
目录下有两个集成测试文件,test_crate2.rs
和tests
。
在Cargo.toml
目录下创建一个包含以下内容的tests
:
[package]
name = "tests"
version = "0.1.0"
edition = "2021"
publish = false
[dev-dependencies]
crate1 = { path = "../crate1" }
crate2 = { path = "../crate2" }
[[test]]
name = "test_crate1"
path = "test_crate1.rs"
[[test]]
name = "test_crate2"
path = "test_crate2.rs"
在工作区目录中运行cargo test
来检查它。
https://stackoverflow.com/questions/71460402
复制相似问题