我想使用参数化测试,发现rstest可以很好地做到这一点。
在main.rs
文件中添加:use rstest::rstest;
并将#[rstest]
也放入main.rs
中在cargo test
上运行良好
但是如果我想用cargo build
构建程序,我会得到这个错误
| use rstest::rstest;
| ^^^^^^ use of undeclared crate or module `rstest`
所以问题是:我必须如何组织我的代码才能使用#[rstest]
,并且还能够构建/运行程序?
1条答案
按热度按时间kognpnkq1#
根据您是否希望使用
rstest
和非测试构建运行代码,您必须在Cargo.toml
中添加rstest
或者您必须从非测试版本中删除使用
rstest
的代码: