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
包含兩個測試函數(shù)
- 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 找出慢測試、泄露測試,并設(shè)置超時時間,超時就自動終止
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 文件夾中的指定函數(shù)(模糊匹配)
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 文件夾中的指定函數(shù)(精確匹配)
cd core_utils cargo nextest run -E 'test(=test_random_string)'
2.11 測試庫中的指定函數(shù)
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
到此這篇關(guān)于rust 如何使用 cargo-nextest 替代 cargo test的文章就介紹到這了,更多相關(guān)rust cargo-nextest 替代 cargo test內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解rust?自動化測試、迭代器與閉包、智能指針、無畏并發(fā)
這篇文章主要介紹了rust?自動化測試、迭代器與閉包、智能指針、無畏并發(fā),本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-11-11關(guān)于Rust?使用?dotenv?來設(shè)置環(huán)境變量的問題
在項目中,我們通常需要設(shè)置一些環(huán)境變量,用來保存一些憑證或其它數(shù)據(jù),這時我們可以使用dotenv這個crate,接下來通過本文給大家介紹Rust?使用dotenv來設(shè)置環(huán)境變量的問題,感興趣的朋友一起看看吧2022-01-01