#unit-testing

macro test_with_parameters

A μ-crate for parameterised unit tests

1 unstable release

0.1.0 Nov 26, 2021

#151 in #unit-testing

MIT/Apache

6KB
77 lines

test_with_parameters

This is a μ-crate which exposes a single attribute, test_with_parameters, which can be used to create parameterised unit tests.

Example

#[cfg(test)]
mod tests {
    #[test_with_parameters(
        [ "input"    , "expected"      ]
        [ None       , "Hello, World!" ]
        [ Some("me") , "Hello, me!"    ]
    )]
    fn hello_tests(input: Option<&str>, expected: &str) {
        assert_eq(expected, hello(input))
    }
}

This desugars to:

#[cfg(test)]
mod tests {
    fn hello_tests(input: Option<&str>, expected: &str) {
        assert_eq(expected, hello(input))
    }

    #[test]
    fn hello_tests_case0() {
        hello_tests(None, "Hello, World!")
    }

    #[test]
    fn hello_tests_case1() {
        hello_tests(Some("me"), hello(input))
    }
}

Dependencies

~1.5MB
~37K SLoC