assert!(a == b)accepts fewer characters than assert_eq!(a, b), and, in my opinion, more readable.
Error messages are more or less the same:
thread 'main' panicked at 'assertion failed: `(left == right)` (left: `1`, right: `2`)', src\main.rs:41
or
thread 'main' panicked at 'assertion failed: 1 == 2', src\main.rs:41
Actually, this issue concerns not only rust; I continue to see these various assertion macros or functions in unit testing systems:
- Cpputest has
CHECKand CHECK_FALSEand CHECK_EQUALetc. - Googletest has
EXPECT_GTand EXPECT_EQetc. - JUnit has
assertEqualsand assertFalsecontinues to work.
Often, there is also a statement for some specific type, such as a string or an array. What's the point?
source
share