A drawing of a giant crab standing in a village.

Workshop: 4 hours

Testing in Rust: an introduction

Bookable for teams – on-site or remote

Workshop description

Book this workshop

Our mentors look forward to working with your team and unlocking new capabilities.
Get in touch
1

Writing your first unit test

Straight into the action: the #[test] annotation and basic assertions! We will wire everything up and get our feedback loop going.

2

Testing failures

Unhappy scenarios are often more important than the happy ones! We will discuss the #[should_panic] annotation as well as the tradeoffs of returning a Result from your tests.

3

The Rust testing zoo

Unit tests are just of the test approaches offered by Rust's built-in testing framework—we have integration and doc tests too. We will look at each category and build a mental framework for choosing the correct testing technique in each context.

4

Running your tests

What is a test? We will take a look under the hood to understand how the Rust built-in testing framework is actually implemented. Armed with this knowledge, we will explore the runtime implications of different approaches for test organisation. We will also cover alternative test runners, such as cargo-nextest.

5

Test helpers: where do they go?

Test code is just as important as production code: you want it to be terse and clearly communicate what is being tested. If you follow this philosophy, you'll soon be trying to extract common logic into test helpers: where should they be located? We will cover the different strategies available (test modules, feature gate, helper crate) and their trade-offs.

6

Beyond assertions

In closing, we will have a look at a few advanced techniques beyond the standard toolkit: snapshot testing (insta) and property-based testing (quickcheck).

Your mentor

Luca Palmieri

Principal Engineering Consultant

Luca Palmieri builds technology products for a living. His current focus is on backend development, software architecture and the Rust programming language. He is the author of "Zero to Production in Rust".

Not the right workshop for you?

Take a look at our wide range of workshops to take your team to the next level
Our workshops

Stay up to date on Rust

Subscribe to our newsletter and stay up to date about the latest events, workshops, and other news around Rust.

Book this workshop

Our mentors look forward to working with your team and unlocking new capabilities.
Get in touch