Rust unit testing: assertion libraries
jorgeortiz.dev·5h·
Discuss: r/rust
Flag this post

At the beginning of this series, I explained how to write a test by decomposing it into three parts: arrange, act, and assert. Since then, we have written several unit tests using that structure. Most of the assertions we’ve written in those tests used the assert_eq!() macro. Sometimes, they were a very obvious way to state what was expected and the actual value that was produced. It’s clear and works well for simple checks. However, in other cases, the syntax is awkward or doesn’t clearly convey what we mean, requiring extra steps or missing necessary functionality.

In this article, I will replace some of the assertions made in the tests that we have written so far with others that are easier to read and write or provide enhanced functionality. Get ready to assert yourself!

##…

Similar Posts

Loading similar posts...