rust 如何使用 cargo-nextest 替代 cargo test
更新時間:2024年05月25日 12:02:35 作者:會編程的大白熊
cargo-nextest 是新一代的rust測試程序,能夠極大提升測試性能,可以完全替代 cargo test 命令,這篇文章主要介紹了rust 如何使用 cargo-nextest 替代 cargo test,需要的朋友可以參考下
cargo-nextest 是新一代的rust測試程序,能夠極大提升測試性能,可以完全替代 cargo test 命令。
1. 安裝
cargo install cargo-nextest
2. 執(zhí)行測試
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 并發(fā)測試
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內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

