Parametrised tests in Rust with named parameters 0 ▲ alexwlchan 49 days ago · Tech · hide · Fediverse post I’ve been revisiting some of my small Rust utilities this week, and I wanted to improve the test suite. There’s a lot of repetition, and I wanted to switch to parametrised tests, a pattern I use a lot in Python and Go. (These are also called “table-driven tests”.) Parameterised tests allow you to write the test logic once, then run it with many different inputs and expected results. This reduces repetition, highlights variation, and simplifies adding new cases. For example, in my thumbnail creator, I want to create a thumbnail with various image formats, and check the thumbnail has the correct filename and dimensions. Rather than copy-pasting test functions, I wanted to declare test cases with named fields, like this: animated_gif: { img_path: "src/tests/animated_squares.gif", target: TargetDimension::MaxWidth(16), expected_filename: "animated_squares.mp4", expected_dims: (16, 16), }, Supporting this syntax required me to create a custom Rust macro. Existing approaches I found three… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town