3 releases

Uses new Rust 2024

0.1.2 Jun 29, 2025
0.1.1 Jun 27, 2025
0.1.0 Jun 27, 2025

#1365 in Procedural macros

Download history 3/week @ 2026-01-21 5/week @ 2026-01-28 9/week @ 2026-02-04 20/week @ 2026-02-18 38/week @ 2026-02-25 5/week @ 2026-03-04 45/week @ 2026-03-11 9/week @ 2026-03-18 15/week @ 2026-03-25 17/week @ 2026-04-01 16/week @ 2026-04-08 24/week @ 2026-04-15 20/week @ 2026-04-29 25/week @ 2026-05-06

71 downloads per month

MIT license

9KB
152 lines

paramtest

With paramtest, you can define multiple sets of input values for a single test function, and each set will be run as a separate test case.

Example

Here's how you can use paramtest in your tests:

use paramtest::paramtest;

#[paramtest(
    one=(1, 2),
    two=(2, 3),
    hundred=(100, 101),
)]
fn add_one(input: u64, output: u64) {
    assert_eq!(output, input + 1)
}

This is effectively the same as writing the following:

#[test]
fn add_one_one() {
    add_on(1, 2);
}

#[test]
fn add_one_two() {
    add_on(2, 3);
}

#[test]
fn add_one_hundred() {
    add_on(100, 101);
}

fn add_one(input: u64, output: u64) {
    assert_eq!(output, input + 1)
}

Each #[paramtest(...)] attribute defines named test cases with their own arguments. The macro will generate a separate test for each case, making your tests concise and easy to maintain.

Tokio Support

Tokio support is enabled by default. If you want to disable it, you can add the tokio feature to your Cargo.toml:

[dependencies]
paramtest = { path = "../proc", features = ["tokio"] }
tokio = { version = "1.45.1", features = ["macros", "rt"] }

And use the #[tokio_paramtest] attribute for your test functions:

#[tokio_paramtest(
    one=(1, 2),
    two=(2, 3),
    hundred=(100, 101),
)]
async fn add_one(input: u64, output: u64) {
    assert_eq!(output, input + 1)
}

Usage

  1. Addparamtest crate as a dependency in your Cargo.toml.
  2. Annotate your test functions with #[paramtest(...)] and provide named cases with argument tuples.

License

MIT

Dependencies

~100–455KB
~11K SLoC