la10736 / rstest

Fixture-based test framework for Rust
Apache License 2.0
1.21k stars 43 forks source link

Feature: Optional label in the `#[case...]` #253

Closed rjzak closed 5 months ago

rjzak commented 6 months ago

Currently, this:

#[rstest]
#[case(include_bytes!("path/to/file.bin"))]
#[case(include_bytes!("path/to/other.bin"))]
fn the_test(#[case] input: &[u8]) {
    do_something(input);
}

Yields:

test module::tests::the_test::case_1 ... ok
test module::tests::the_test::case_2 ... ok

It would be nice to have:

#[rstest]
#[case_label("file.bin qwerty", include_bytes!("path/to/file.bin"))]
#[case_label("other.bin bazfoo", include_bytes!("path/to/other.bin"))]
fn the_test(#[case] input: &[u8]) {
    do_something(input);
}

Which would yield:

test module::tests::the_test::file.bin qwerty ... ok
test module::tests::the_test::other.bin bazfoo ... ok

So if there's an error with a specific case, it's easier to see which one failed.

la10736 commented 6 months ago

First of all you can have something that is quite the same with the following code

#[rstest]
#[case::file_bin__qwerty(include_bytes!("path/to/file.bin"))]
#[case::other_bin__bazfoo(include_bytes!("path/to/other.bin"))]
fn the_test(#[case] input: &[u8]) {
    do_something(input);
}

Sadly you cannot label your tests with an unconstrained string like in kotlin because the rust framework show just the test function path and tests name should be valid identities.