#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

#512 in Testing

Download history 31/week @ 2024-07-22 159/week @ 2024-07-29 309/week @ 2024-08-05 155/week @ 2024-08-12 229/week @ 2024-08-19 138/week @ 2024-08-26 340/week @ 2024-09-02 134/week @ 2024-09-09 329/week @ 2024-09-16 176/week @ 2024-09-23 136/week @ 2024-09-30 127/week @ 2024-10-07 66/week @ 2024-10-14 126/week @ 2024-10-21 115/week @ 2024-10-28 24/week @ 2024-11-04

340 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

~86KB