Brussels / 3 & 4 February 2018

schedule

Testing in Rust

A Primer in Testing and Mocking


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.

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 ownership semantics make dependency mocking 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
  • generate large amounts of test data for fuzz testing in 2-3 lines of code

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

Photo of Donald Whyte Donald Whyte

Links