
In this starting section we'll cover the major content of the course as well as some tips on how to get the most out of it.
Let's get into modules a little more deeply and see how we can use them for testing
This video looks at mocking the internal calls of functions by using generics
Programming with Rust is challenging. Even after spending substantial time learning and building apps with Rust, creating fully Mocked Unit Tests can be quite difficult.
A real Unit Test should have its calls Mocked and only allow the Unit Under Test to run real code. But how does one do this with Rust? Dependency Injection is kind of doable, but dealing with Traits and their usage constraints can sometimes feel like a wrestling match.
Although Rust has its own form of Interface, Rust is not an Object Oriented Programming language and does not have inheritance--which can make it unclear as to how to use Traits to perform patterns like Dependency Injection and creation of test Mocks. In addition the usage of async functions through the Tokio Runtime adds additional complexity to our tests. How do I force my tests to wait until certain variables are set? How do I share fixtures that are set globally across individual tests?
In this course we'll learn about various design patterns we can use to help build Rust based Unit Tests that are truly Mocked, and not Integration Tests masquerading as Unit Tests. We'll also learn about several crates that can help with things like pre-setting global variables to be used by our tests before the tests are run, mocking crates that can help us Mock out services, and utilities that can help set random values to add robustness to our tests.
Bonus Content shows how to use Generics to inject our Mocks into the internal implementation of functions. This allows us to Mock internal calls within functions without actually modifying the working function itself.