- Learning Rust
- Paul Johnson Vesa Kaihlavirta
- 68字
- 2021-07-02 23:07:14
Assert yourself!
Unit testing provides the developer with a number of methods called assertion methods:
#[test] fn multiply() { assert_eq!(5, 2 * 3); }
In the preceding code snippet, we use the assert_eq! (assert equal) macro. The first argument is the answer expected, and the second argument is what is being tested. If 2 * 3 = 5, then the assertion is true and passes the unit test.
推薦閱讀