简体   繁体   English

是否可以只运行带有货物测试的单元测试?

[英]Is it possible to run only unit tests with cargo test?

I have a workspace consisting of both lib and bin crates.我有一个由 lib 和 bin 板条箱组成的工作区。 Running cargo test --lib skips the binary crates.运行 cargo test --lib跳过二进制包。

--bins and --lib are not exclusive, you can use both and it'll run the tests in both categories: --bins--lib不是独占的,您可以同时使用它们,它会在两个类别中运行测试:

$ cargo test --bins
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running target/debug/deps/foo-c982c1477aaaf33d

running 1 test
test test_bins ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

$ cargo test --lib
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running target/debug/deps/foo-532806c187f0c643

running 1 test
test test_lib ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

$ cargo test --bins --lib
    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running target/debug/deps/foo-532806c187f0c643

running 1 test
test test_lib ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/foo-c982c1477aaaf33d

running 1 test
test test_bins ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

The test project does have an integration test which gets run if no target is provided:测试项目确实有一个集成测试,如果没有提供目标,它就会运行:

$  cargo test
   Compiling foo v0.1.0 (foo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.27s
     Running target/debug/deps/foo-532806c187f0c643

running 1 test
test test_lib ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/foo-c982c1477aaaf33d

running 1 test
test test_bins ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/test_foo-79419bfea3135abf

running 1 test
test test_integration ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests foo

running 0 tests

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM