Can I set custom labels for test functions?

cargo test shows test results like this;

running 3 tests
test tests::test_f32_at_least_returns_self_if_self_eq_min ... ok
test tests::test_f32_at_least_returns_min_if_self_lt_min ... ok
test tests::test_f32_at_least_returns_self_if_self_gt_min ... ok

Is there any way to get results like this?
In other words, can I use custom labels for test functions?

test `f32::at_least(min) returns self if self == min` ... ok
test `f32::at_least(min) returns min if self < min` ... ok
test `f32::at_least(min) returns self if self > min` ... ok
1 Like

This isn't possible with cargo test.

You can use namespaces to help make things easier to read (e.g. f32::at_least::returns_self::if_self_eq_self), but it's not possible to use a custom label for your tests.

1 Like

Is that possible without creating a nesting hell like this?

mod a {
    mod b {
        mod c {
            #[test]
            fn xyz() {
            }
        }
    }
}

Not really. You could move the innermost mod to a file. If you don't want the same mess with directories, you can use #[path] on the mod.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.