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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Test functions5m 6s
-
(Locked)
assert! macro3m 57s
-
(Locked)
Custom failure messages3m 59s
-
(Locked)
assert_eq! and assert_ne! macros2m 8s
-
(Locked)
should_panic! macro4m 32s
-
(Locked)
Controlling test execution8m 3s
-
(Locked)
Unit tests4m 44s
-
(Locked)
Integration tests5m 7s
-
(Locked)
Challenge: Write automated tests1m 45s
-
(Locked)
Solution: Write automated tests2m 41s
-
(Locked)
-