#unit-testing #mocking #logger #logging #test

mock-logger

A mock logging implementation for unit testing

4 releases

0.1.3 Aug 20, 2023
0.1.2 Aug 20, 2023
0.1.1 Jul 10, 2023
0.1.0 Jul 10, 2023

#317 in Testing

Download history 26/week @ 2024-04-14 34/week @ 2024-04-21 19/week @ 2024-04-28 38/week @ 2024-05-05 45/week @ 2024-05-12 52/week @ 2024-05-19 21/week @ 2024-05-26 37/week @ 2024-06-02 113/week @ 2024-06-09 103/week @ 2024-06-16 144/week @ 2024-06-23 149/week @ 2024-06-30 841/week @ 2024-07-07 16/week @ 2024-07-14 24/week @ 2024-07-21 166/week @ 2024-07-28

1,078 downloads per month

MIT license

6KB
110 lines

Mock Logger for Rust

This is a testing utility providing a mock logging implementation that can be used to verify correctness in your own logging.

Usage

use log::info;

fn log_something() {
    info!("something");
}
#[cfg(test)]
mod test {
    use mock_logger::MockLogger;
    use super::*;
    
    #[test]
    fn test_logging() {
        mock_logger::init();
        log_something();
        MockLogger.entries(|entries| {
            assert_eq!(entries.len(), 1);
            assert_eq!(entries[0].level, log::Level::Info);
            assert_eq!(entries[0].body, "something");
        });
    }
}

Dependencies

~87KB