From the course: Advanced Rust: Managing Projects

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

assert_eq! and assert_ne! macros

assert_eq! and assert_ne! macros - Rust Tutorial

From the course: Advanced Rust: Managing Projects

assert_eq! and assert_ne! macros

- [Instructor] All three variations of the assert macro enable us to optionally provide a custom message to convey extra information that might help with debugging when an assertion fails. Any additional arguments passed after the argument required for the assert macro will be passed to the format macro to print along with the failure message. To demonstrate that, let's build on the previous example, using the three assert macros to test our add to function. Now, instead of calling the add to function as part of the expression for the assert macro on line 11, let's use a variable to capture that result and then use that result in the expression. Next, let's add a second argument with a message "Expected four result was," and then curly braces for a placeholder and we'll add a third argument after that with the result that occurred. Remember, all additional arguments after the first Boolean expression will be handed off to…

Contents