6 Unit testing

 

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.

6.1 How testing is different in Rust

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.

6.2 Review of built-in testing features

 
 
 

6.3 Testing frameworks

 

6.4 What not to test, or why the compiler knows better than you

 
 

6.5 Handling parallel test special cases and global state

 

6.6 Thinking about refactoring

 
 

6.7 Refactoring tools

 
 

6.7.1 Reformating

 
 

6.7.2 Renaming

 
 

6.7.3 Relocating

 
 
 
 

6.7.4 Rewriting

 
 
 

6.8 Code coverage

 
 
 

6.9 Dealing with a changing ecosystem

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest