Rust tests can be defined as nested modules or as standalone files.

Nest modules defines unit tests. They can be defined by a separate module annotated by some attributes:

#[cfg(test)]
mod tests {
    use super::*;
 
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}

Standalone files in the top-level /tests folder defines integration tests. It is best practice to put them into a single crate.

Test Only Dependencies

We can add dev-dependencies

[dev-dependencies]
tempdir = "0.3"

Specific Tests

References