Cargo 測試

2021-09-27 13:56 更新

測試

Cargo 可以使用cargo test命令運行您的測試。Cargo 尋找在兩個地方運行的測試 :在你src中的每個文件,和tests/中的任何測試。測試你的src文件應該是單元測試,并在tests/中的應該是整合式測試。因此,您需要將包裝箱導入到tests的文件中.

這是在我們的項目中,運行cargo test的一個例子,目前沒有測試:

$ cargo test
   Compiling rand v0.1.0 (https://github.com/rust-lang-nursery/rand.git#9f35b8e)
   Compiling hello_world v0.1.0 (file:///path/to/project/hello_world)
     Running target/test/hello_world-9c2b65bbb79eabce

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

如果我們的項目有測試,我們會看到更多的輸出與正確的測試數(shù)量.

您還可以通過傳遞過濾器,來運行特定測試:

$ cargo test foo

這將運行任何匹配的foo測試.

cargo test還運行其他檢查。例如,它將編譯您包含的任何示例(examples),并且還將測試文檔中的示例。請看在 Rust 文檔中的測試指南,了解更多詳細信息.



以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號