Skip to content

Parametrized tests support #19

Open

Description

@epage
No description provided.

Activity

  1. added
    A-pytestArea: pytest-like framework implemented on top of the new harness
    C-enhancementCategory: Raise on the bar on expectations
    on Apr 25, 2023
  2. added this to the json output milestone on Feb 12, 2024
  3. added a commit that references this issue on Mar 5, 2025
  4. epage commented on Oct 20, 2025

    @epage
    CollaboratorAuthor

    From #13 (comment)

    I'm playing with the idea of

    #[test]
    #[ty(T=[Foo, Bar])]
    #[const(N=[1, 2, 3])]
    #[param(n=[1,2,3])]
    fn test<const N: usize, T>(param: usize) {
    }
    • Fits with having #[should_panic] and #[ignore]

    • Assuming we do a matrix of options. People need to use tuples to not do matrix

    Compared to rustest

    #[test(params:u32=[1,2,5])]
    fn test(param: Param) {
        assert!([1,2,5].contains(&param))
    }
    • Requires a proxy type with references

    • Requires using tuples

    Compared to divan

    #[divan::bench(args = [Arg::A, Arg::B])]
    fn bench_args(arg: Arg) {
        // ...
    }
    
    #[divan::bench(consts = [1000, LEN, len()])]
    fn init_array<const N: usize>() -> [i32; N] {
        let mut result = [0; N];
    
        for i in 0..N {
            result[i] = divan::black_box(i as i32);
        }
    
        result
    }
    
    #[divan::bench(types = [&str, String])]
    fn from_str<'a, T>() -> T
    where
        T: From<&'a str>,
    {
        divan::black_box("hello world").into()
    }
  5. epage commented on Oct 20, 2025

    @epage
    CollaboratorAuthor

    Should #[ignore] functions have access to parameters and fixtures?

  6. epage commented on Oct 29, 2025

    @epage
    CollaboratorAuthor

    https://crates.io/crates/parameterized/2.0.0 has lists of values for each paramter

        #[parameterized(fruit = {
            Fruit::Apple, Fruit::Pear, Fruit::Bramble(BrambleFruit::Blackberry)
        }, name = {
            "apple", "pear", "blackberry"
        })]
        fn a_fruity_test(fruit: Fruit, name: &str) {
            assert_eq!(fruit.name_of(), name)
        }

    while https://crates.io/crates/yare/3.0.0 has named sets of parameters

    #[parameterized(
      seeding_randomness_with_two_dice_rolls = 
      {
        roll_dice(&AtomicU32::new(0)),                              // <- This is an expression (a function call)
        {                                                           // <- This is also an expression (a block expression)
          let from_half = roll_dice( &AtomicU32::new(u32::MAX / 2));
          let from_max = roll_dice( &AtomicU32::new(u32::MAX));
          
          u8::min(from_half, from_max)
        }
      }
    )]
    fn dicey(seed1: u8, seed2: u8) {
        // Creating a base seed in a complicated way for the sake of it.
        let max = u8::max(seed1, seed2);
        let seed = AtomicU32::new(u32::from(max));
    
        let out_of_bounds_values = (0..1000)         // roll the dice 1000 times
            .map(|_| roll_dice(&seed))
            .find(|value| !(1..=6).contains(value)); // check that the outputs of the dice are just 1, 2, 3, 4, 5 or 6. 
    
        assert!(out_of_bounds_values.is_none());
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-pytestArea: pytest-like framework implemented on top of the new harnessC-enhancementCategory: Raise on the bar on expectations

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions