conferences | speakers | series

Testing in Rust

home

Testing in Rust
FOSDEM 2018

ABSTRACT

Rust is designed for building low-level systems processes that are reliable and safe. Nevertheless, it is still important for developers to ensure their code is doing the right thing. To achieve this, Rust has a rich set of built-in testing tools for writing unit tests.

In this talk we cover general unit testing techniques for Rust. We will also demonstrate how to mock out complex dependencies using the double crate. Examples will range from simple cases to complex cases that you'll often see when testing real world systems.

The talk is suitable for both novice and experienced Rust developers, as well as non-Rust developers who are interested in learning more about the language.

DETAILED OVERVIEW

Rust is designed for building low-level systems processes that are reliable and safe. Nevertheless, it is still important for developers to ensure their code is doing the right thing. To achieve this, Rust has a rich set of built-in testing tools for writing unit tests.

When writing unit tests, we often need to mock dependencies that are complex to set up or access external resources (e.g. databases and APIs). Rust's heavy emphasis on generic metaprogramming and borrow semantics make mocking dependencies non-trivial. Thankfully, the double crate (https://github.com/DonaldWhyte/double) abstracts the complexities of mocking in Rust away from you.

In this talk we cover general unit testing techniques for Rust. We will also demonstrate how to mock out dependencies using double. Examples will range from simple cases to complex cases that you'll often see when testing real world systems. By the end of the talk, viewers will be able to:

  • write test modules and documentation tests
  • mock out complex dependencies for simpler / more deterministic unit tests
  • perform powerful matching on generated outputs

This talk is suitable for both novice and experienced Rust developers, as well as non-Rust developers who are interested in learning more about the language.

Speakers: Donald Whyte