Is it possible to run only unit tests with cargo test? I have a workspace consisting of both lib and bin crates. Running cargo test --lib skips the binary crates.
--bins and --lib are not exclusive, you can use both and it'll run the tests in both categories:
$ 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
note that the test project does have an integrastion test which gets run if no target is provided:
$ cargo test
Compiling foo v0.1.0 (/home/odoo/odoo/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