目录- 1. 安装
- 2. 执行测试
- 2.1 查找所有测试
- 2.2 找出慢测试、泄露测试,并设置超时时间,超时就自动终止
- 2.3 并发测试
- 2.4 重试失败的测试用例
- 2.5 运行上次失败的测试
- 2.6 测试指定的包
- 2.7 测试 lib 中的所有测试用例
- 2.8 运行项目中的所有测试
- 2.9 测试 tests 文件夹中的指定函数(模糊匹配)
- 2.10 测试 tests 文件夹中的指定函数(精确匹配)
- 2.11 测试库中的指定函数
- 2.12 测试 tests 的一个文件
cargo-nextest 是新一代的rust测试程序,能够极大提升测试性能,可以完全替代 cargo test 命令。
1. 安装
cargo install cargo-nextest
2. 执行测试
project
├── Cargo.toml
├── LICENSE
├── README.md
├── build.rs
├── core_utils
│ ├── Cargo.toml
│ ├── build.rs
│ ├── deny.toml
│ ├── src
│ │ ├── random
│ │ │ ├── arbitrary
│ │ │ │ ├── arbitrary.rs
│ │ │ │ ├── mod.rs
│ │ │ │ ├── option.rs
│ │ │ │ └── result.rs
│ │ │ ├── gen.rs
│ │ │ ├── mod.rs
│ │ │ └── utils.rs
│ │ │ └── lib.rs
│ ├── tests
│ │ ├── test_random.rs
tests/test_random.rs 包含两个测试函数
- test_random_string
- test_random_string_2
src/random/option.rs 包含测试
#[cfg(test)]
mod tests {
use crate::random::arby;
#[test]
fn test_option() {
let x = arby::<Option<bool>>(5);
println!("{:#?}", x);
let x = arby::<Option<bool>>(5);
println!("{:#?}", x);
let x = arby::<Option<bool>>(5);
println!("{:#?}", x);
}
}
2.1 查找所有测试
cargo nextest list
cargo nextest list test_random
2.2 找出慢测试、泄露测试,并设置超时时间,超时就自动终止
cargo nextest run --slow-timeout 60 -leak-timeout 1024
2.3 并发测试
cargo nextest run --release -- --jobs 4
cargo nextest --jobs 4
2.4 重试失败的测试用例
cargo nextest run --retries 3
2.5 运行上次失败的测试
cargo nextest run -- --failed
2.6 测试指定的包
cargo nextest run -p core_utils
2.7 测试 lib 中的所有测试用例
cd core_utils
cargo nextest run :
或
cargo nextest run --lib
2.8 运行项目中的所有测试
cargo nextest run
# 会包含文档字符串中的测试用例
cargo nextest run --tests
2.9 测试 tests 文件夹中的指定函数(模糊匹配)
cd core_utils
cargo nextest run test_random_string
cargo nextest run -- test_random_string
cargo nextest run -E 'test(test_random_string_2)'
cargo nextest run -E 'test(test_random)'
2.10 测试 tests 文件夹中的指定函数(精确匹配)
cd core_utils
cargo nextest run -E 'test(=test_random_string)'
2.11 测试库中的指定函数
cargo nextest run --lib random::arbitrary::option::tests::test_option
cargo nextest run random::arbitrary::option::tests::test_option
cargo nextest run random::arbitrary::option::tests
cargo nextest run random::arbitrary::option::
cargo nextest run random::arbitrary:
cargo nextest run random::
2.12 测试 tests 的一个文件
cargo nextest run --test test_random
到此这篇关于rust 如何使用 cargo-nextest 替代 cargo test的文章就介绍到这了,更多相关rust cargo-nextest 替代 cargo test内容请搜索琼殿技术社区以前的文章或继续浏览下面的相关文章希望大家以后多多支持琼殿技术社区!
您可能感兴趣的文章:- Python安装jupyter notebook报pywinpty缺少Rust和Cargo问题
- 深入理解Rust中Cargo的使用
- Rust中Cargo的使用详解
- Rust中的Cargo构建、运行、调试
- 使用Cargo工具高效创建Rust项目
- 使用cargo install安装Rust二进制工具过程
|