Rust Tests Test a function


fn to_test(output: bool) -> bool {

#[cfg(test)] // The module is only compiled when testing.
mod test {
    use super::to_test;

    // This function is a test function. It will be executed and
    // the test will succeed if the function exits cleanly.
    fn test_to_test_ok() {
        assert_eq!(to_test(true), true);

    // That test on the other hand will only succeed when the function
    // panics.
    fn test_to_test_fail() {
        assert_eq!(to_test(true), false);

(Playground link)

Run with cargo test.