How to Test Private Functions in Rust

Test private Rust functions by adding a #[cfg(test)] module and using use super::* to access internal items.

Add the #[cfg(test)] attribute to your test module and use use super::*; to access private functions within that module.

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_private_function() {
        let result = private_helper();
        assert_eq!(result, 42);
    }
}

fn private_helper() -> i32 {
    42
}