In Rust, how do I test a code in a sub-sub-directory, with cargo test command?
program
`─ src
| `─ main.rs
`─ tests
`─ foo
`─ foo.rs
main.rs:
fn main() {
}
foo.rs:
mod test_foo {
#[test]
fn test_foo() {
assert!(true);
}
}
One way would be to create tests/tests.rs with the following contents:
mod foo {
mod foo; // this will include `tests/foo/foo.rs`
}
If you run cargo test after this, it will run the test_foo test function:
$ cargo test
Running target/debug/tests-0b79a5e208e85ac6
running 1 test
test foo::foo::test_foo::test_foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With