While I like Rust's `[#test]` can be placed anywhere and will be found/run by cargo test, I think there should also be something like `[#test_context]` where you receive a handle to the test framework's entry point (a little like Go) and from there you just write code to create tests... this is a stupid simple way to solve every problem mentioned in this post. Dart has something like this, and it's amazing for me to realize that its totally simplistic solution makes everything those complex Java testing frameworks do (test by example cases, skip depending on a function's return value, group tests into sub-tests etc.) not just possible, but easier and more fun to use as it's just "normal" code (your IDE can autocomplete your stuff so you don't need to google every tinme for the magic combination of annotations/parameters/types to use).
This is what it may look like in Rust:
#[test_context]
fn make_tests(t: &mut TestHarness) {
t.newGroup("group 1", |t| {
t.newTest("test something", |t| {
assert_eq(...);
});
for (input, expected) in &[("a", "a1"), ("b", "b1")] {
t.newTest(format!("my_fun({}) == {}", input, expected), || {
assert_eq(my_fun(input), expected);
}),
}
});
}
Please stop using Java annotation-like stuff for this kind of thing, it just limits what you can do in exchange for looking a little prettier (but being vastly more complex when the whole implementation is taken into consideration).