A schematic drawing of a grid with files on top and connecting lines between the files.

All Rust Workshops

Testing in Rust: going beyond the basics

1 day Bookable for teams – on-site or remote

About This Workshop

No application is an island: you need to interact with third-party APIs, databases and who knows what else. Testing those interactions is tricky, to say the least! This workshop will focus on expanding your Rust testing toolkit, going beyond the basic techniques you're already familiar with. At the end of the session, you'll have a strategy to test most of the scenarios that are relevant for a complex Rust application.

The workshop is designed for software developers who have a good understanding of Rust's basic concepts and want to move beyond the built-in testing toolkit.

If you are new to Rust instead, you might be interested instead in our introductory testing workshop.

Bookable for teams

1 day

On-site or remote

Book for your team

Syllabus

  1. Expanding your toolbox: better assertions

    The Rust standard library provides a few macros to perform assertions in your tests: assert!, assert_eq!, etc. They are good enough to get started, but the error messages they produce will often fail to keep up with the complexity of your assertions: we'll explore different libraries to boost the clarity of your test failures.
  2. Expanding your toolbox: snapshot testing

    Snapshot testing is a technique that allows us to capture the output of a system under test and compare it with a previously saved version. It is quite useful when working with complex data that might change frequently, such as HTML or error messages. We will explore how to use the insta crate to implement snapshot testing and manage the snapshots lifecycle.
  3. Isolating your tests: the filesystem

    All tests in Rust share the same filesystem as the underlying host, a problematic situation when multiple tests want to interact with the "same" files or touch directories that could affect the behaviour of the system they are being executed from. We will explore various techniques to manage this scenario, including the tempfile crate.
  4. Isolating your tests: the database

    The database is another shared resource that can cause problems when running tests in parallel. We will explore how to use Docker to run an isolated database instance for each test, and how to use the sqlx crate to manage the database lifecycle.
  5. Isolating your tests: HTTP mocking

    It is undesirable to have tests that hit real HTTP endpoints from third-party APIs, for a variety of reasons. We will explore how to use the wiremock crate to shield our tests from the outside world and make assertions on the HTTP requests that are being sent.
  6. Isolating your tests: mocks, stubs and fakes

    In order to isolate the behaviour of a system under test, it is not unusual to replace some of its dependencies with "fake" implementations. We will explore the different types of fakes and how to use them in Rust. We will review, in particular, the mockall crate and the testing implications of using generics and dynamic dispatch for polymorphism.
  7. Custom test runners: what is a test?

    We will take a look under the hood to understand how the Rust built-in testing framework works. 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.
  8. Custom test runners: executing logic before and after a test run

    It is often desirable to execute the same logic before and after each test in our suite. We will explore a variety of techniques to achieve this, from a bespoke #[test_case] procedural macro to a custom test harness (via libtest_mimic).
  9. Custom test runners: capstone project

    We will combine everything we have learned so far into an easy-to-use setup that allows you to run black-box tests against a real database and a real HTTP server, without having to orchestrate multiple commands—just cargo test and you are good to go!

FAQ

Placeholder! What software do I need to have?

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl. Ut eu sollicitudin magna. Nullam varius neque ante, a pulvinar ipsum luctus id.

Placeholder! What hardware do I need to have?

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl. Ut eu sollicitudin magna. Nullam varius neque ante, a pulvinar ipsum luctus id.

Placeholder! How will the workshop be held?

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl. Ut eu sollicitudin magna. Nullam varius neque ante, a pulvinar ipsum luctus id.

Placeholder! How will the workshop be held?

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl. Ut eu sollicitudin magna. Nullam varius neque ante, a pulvinar ipsum luctus id.

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".

Our Attendees Say...

Extremely well set up!
Onsite attendee
Well constructed exercises that cover various testing topics. Well done.
Onsite attendee

Who we are

We are Mainmatter and we Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam in nisi sed eros eleifend scelerisque a eu nisl.

Rust Workshops

We offer a range of workshops bookable for teams that want to grow – on-site or remote. We're also happy to prepare custom workshops – get in touch with us to talk about what curriculum fits your team best!

We are Trusted by

Bookable for teams

1 day

On-site or remote

Book for your team

Can't Find the Right Workshops for Your Team?

We are happy to tailor the curriculum to your needs. We can combine multiple workshops, pick and choose modules, as well as develop new content if desired.
Get in Touch

Book This Workshop

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

Send us a message

Your message is being sent…

Unable to send message.

Please try again later or contact us at info@mainmatter.com

Thank you!

We will be in touch soon.

Testing in Rust: going beyond the basics