Ability to give tests custom names

Currently tests are printed using the functions "path".

In one of my projects, I currently generate a test suite (using build.rs) from a markdown file. The case titles in the markdown are in a "human" form with mixed capitalisation, usage of special symbols and punctuation. To produce a valid Rust function name I have to transform these titles. This unfortunately means that cargo tests output does not quite map back to the file which means I have to do a bit of searching and approximation to figure out the mappings.

image

It would be great if there was a way to "override" the name printed in the test by given extra tokens to the #[test] attribute.

e.g.

#[test(name = "My name")]
fn my_name() { }

This would greatly benefit the debugging of these tests.

test My Name ... ok

Additionally it would be great if there was a details property. This could be printed for failing tests (or under cargo test -- --verbose) that would also help managing these generated tests.

#[test(name = "My name", details = "at ./specification.md:120")]
fn my_name() { }
6 Likes

From Skippable Tests - #5 by epage

For me, what I'm hopeful for your case is to develop a custom test harness that supports data-driven tests that would call out the path to the data (and maybe when we report the relevant file/line of a test in json, we point back to the data). Unsure if this would fully work with your case or if code-gen is a hard requirement. Even if it is, I think this kind of scheme would work.

6 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.