rust 内部包含#[rstest]的货物构建失败

8yoxcaq7  于 2023-01-21  发布在  其他
关注(0)|答案(1)|浏览(102)

我想使用参数化测试,发现rstest可以很好地做到这一点。
main.rs文件中添加:use rstest::rstest;并将#[rstest]也放入main.rs中在cargo test上运行良好
但是如果我想用cargo build构建程序,我会得到这个错误

| use rstest::rstest;
 |     ^^^^^^ use of undeclared crate or module `rstest`

所以问题是:我必须如何组织我的代码才能使用#[rstest],并且还能够构建/运行程序?

kognpnkq

kognpnkq1#

根据您是否希望使用rstest和非测试构建运行代码,您必须在Cargo.toml中添加rstest

[dependencies]
rstest = "*"

或者您必须从非测试版本中删除使用rstest的代码:

#[cfg(test)]
use rstest::rstest;

相关问题