External Publication
Visit Post

Change error message of a failing `assert_eq!`

Rust Internals [Unofficial] March 30, 2026
Source

mathstuf:

I tend to do actual, expected because actual is usually just a variable reference while expected can be a large literal or other more verbose expression and the last argument is far more amenable to reformat splay than the former (IMO).

jUnit and related use the opposite order for a similar reason: they're assuming that expected is often a small literal, and actual is often a function call with a bunch of parameters (the call that's being tested). This is also the documented convention used in googletest for other languages, though apparently not the Rust port as mentioned above?

I've rarely seen any test framework for any language which documents the order as actual, expected - most either don't assign a specific meaning or use expected, actual.

Discussion in the ATmosphere

Loading comments...