This chapter covers
- Understanding how unit testing is unique in Rust
- Exploring unit testing dos and don’ts, features, and frameworks
- Discussing unit testing with parallel code
- Writing unit tests that consider refactoring
- Exploring tools to help with refactoring
- Measuring code covered by tests
- Testing strategies for dealing with Rust’s ecosystem
Unit testing is one way to improve code quality, as it can catch regressions and ensure code meets requirements before shipping. Rust includes a built-in unit testing framework to make your life easier. In this chapter, we’ll review some of the features Rust provides and discuss some of the shortfalls of Rust’s unit testing framework—and how to overcome them.
Before we jump into the details of Rust’s unit testing features, we should talk about the differences between Rust and other languages and how they relate to unit testing. For those coming from languages like Haskell or Scala, you may find Rust has similar properties when it comes to testing. Compared to most languages, however, Rust varies greatly, in that the kinds of unit tests you might see in other languages aren’t necessary in Rust.