El paquete GoogleTest permite hacer test más legibles:
use googletest::prelude::*;
#[googletest::test]
fn test_elements_are() {
let value = vec!["foo", "bar", "baz"];
expect_that!(value, elements_are!(eq("foo"), lt("xyz"), starts_with("b")));
}
Podemos agregar la dependencia con este comando :
$ cargo add googletest
Updating crates.io index
Adding googletest v0.11.0 to dependencies.
Features:
- anyhow
- proptest
Updating crates.io index
Y si corremos el test, tendremos este resultado:
Compiling hello_cargo v0.1.0 (/home/emanuel/Projects/rust/hello_cargo)
Finished test [unoptimized + debuginfo] target(s) in 6.29s
Running unittests src/main.rs (target/debug/deps/hello_cargo-4557c2a679e4325f)
running 1 test
test test_elements_are ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Dejo link: https://github.com/google/googletest-rust