How to Use #[cfg] for Conditional Compilation

Use the #[cfg(test)] attribute to include test modules only during test execution.

Use the #[cfg(test)] attribute above a module to include it only when running tests.

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

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}

Run the tests with cargo test to compile and execute the conditional code.