Rust test folder location
1 min read
Embedded test module
These tests can interact with private variables. Unit tests go here.
// Some code I want to test
#[cfg(test)]
mod tests {
// Import the code I want to test
use super::*;
// My tests
}
tests
folder
External These tests have the same level of access as an external crate importing this one. Integration tests go here.
ā ls
src/
tests/
Cargo.toml
Cargo.lock
...
Combine all tests into one module - crate/tests/integration/*
instead of multiple .rs
files in crate/tests/
. Otherwise, each individual file is compiled into a separate binary.
- Doc
Same level of access as #2
/// Check if a number is even.
/// ```rust
/// use zero2prod::is_even;
///
/// assert!(is_even(2));
/// assert!(!is_even(1));
/// ```
pub fn is_even(x: u64) -> bool {
x % 2 == 0
}
Sources