This chapter covers
- Understanding how unit testing in Rust differs from other languages
- Reviewing Rust’s unit testing features
- Exploring testing frameworks
- Dos and don’ts for unit testing in Rust
- Unit testing with parallel code
- Writing unit tests with refactoring in mind
- Exploring tools to help with refactoring
- Measuring code covered by tests
- Testing strategies for dealing with Rust’s rapidly changing ecosystem
Unit testing is one way to improve code quality by catching regressions and ensuring 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 it relates 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 kind of unit tests you might normally see in other languages isn’t necessary in Rust.