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

mod tests {
    // Import the code I want to test
    use super::*;

    // My tests

External tests folder

These tests have the same level of access as an external crate importing this one. Integration tests go here.

āžœ ls

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.

  1. 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