The Rust assert_eq! macro compares two values for equality and panics when they differ. In tests, the framework catches that panic, marks the test as failed, and reports both values using their Debug representations. section 7.1
A passing equality assertion
let result = 2 + 2; assert_eq!(result, 4); section 7.1
A failing equality assertion
let result = 2 + 2; assert_eq!(result, 5); The test output reports an assertion failure with left: 4 and right: 5, then marks the test as failed.
Use assert_eq! alongside the surrounding Rust testing tools:
- Place assertions in functions marked with #[test]. section 7.1
- Run tests with cargo test; use -- --nocapture when test output must be displayed. section 7.3
- Use assert! for Boolean conditions, or unwrap() and expect() when merely validating that an operation does not return an error. section 7.1

