3 stable releases

1.0.2 Aug 19, 2022
1.0.1 Feb 22, 2021
1.0.0 Dec 30, 2020

#46 in Testing

Download history 567/week @ 2022-06-06 724/week @ 2022-06-13 531/week @ 2022-06-20 541/week @ 2022-06-27 914/week @ 2022-07-04 617/week @ 2022-07-11 946/week @ 2022-07-18 649/week @ 2022-07-25 1056/week @ 2022-08-01 630/week @ 2022-08-08 616/week @ 2022-08-15 1016/week @ 2022-08-22 1153/week @ 2022-08-29 540/week @ 2022-09-05 729/week @ 2022-09-12 629/week @ 2022-09-19

3,094 downloads per month
Used in fewer than 11 crates

MIT/Apache

10KB
107 lines

Yare

Procedural macro based parameterized testing library. Run a test case with many different inputs. Test cases can be defined using the 'parameterized' attribute instead of the 'test' attribute.

Examples:


Example: Add5

fn add5<T: Into<u32>>(component: T) -> u32 {
    component.into() + 5
}

#[cfg(test)]
mod tests {
    use super::*;
    use yare::parameterized;
    
    #[parameterized(
        zero_plus_five = { 0, 5 },
        one_plus_five = { 1, 6 },
        two_plus_five = { 2, 7 },
    )]
    fn test_add5(input: u16, expected: u32) {
        assert_eq!(add5(input), expected);
    }
}

Example: Fruits

enum Fruit {
    Apple,
    Bramble(BrambleFruit),
    Pear,
}

trait NameOf {
    fn name_of(&self) -> &str;
}

impl NameOf for Fruit {
    fn name_of(&self) -> &str {
        match self {
            Fruit::Apple => "apple",
            Fruit::Bramble(fruit) => fruit.name_of(),
            Fruit::Pear => "pear",
        }
    }
}

enum BrambleFruit {
    Blackberry,
}

impl NameOf for BrambleFruit {
    fn name_of(&self) -> &str {
        match self {
            BrambleFruit::Blackberry => "blackberry",
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use yare::parameterized;
    
    #[parameterized(
        apple = { Fruit::Apple, "apple" },
        pear = { Fruit::Pear, "pear" },
        blackberry = { Fruit::Bramble(BrambleFruit::Blackberry), "blackberry" },
    )]
    fn a_fruity_test(fruit: Fruit, name: &str) {
        assert_eq!(fruit.name_of(), name)
    }
}

Imports

If you prefer not to import this library (with use yare::parameterized;) in every test module, you can put the following snippet at the top of your crate root:

#[cfg(test)]
#[macro_use]
extern crate yare;

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~225–630KB
~15K SLoC