Although the Rust compiler ensures safe memory management, it cannot formally verify the correctness of a program's logic. Fortunately, Rust also comes with great libraries and documentation for writing unit and integration tests. When you initiate code with Cargo, test scaffolding is automatically generated to simplify the developer experience. Basic testing concepts and syntax are covered in depth in Chapter 11 of the Rust Book.
There's also more rigorous testing systems ranging from mocking and fuzzing to formal verification. See quickcheck for an example of a property-based testing framework ported from Haskell to Rust.
Kitchen Modules with Unit Tests
The following modules in the
kitchen have partial unit test coverage
Cooking in the Kitchen (Running Tests)
To run the tests, clone the repo
$ git clone https://github.com/substrate-developer-hub/recipes
Enter the path to the module to be tested
recipes git:(some-branch) ✗ cd kitchen/modules/<some-module>
For example, to test
module-constant-config, used in Configurable Constants,
recipes git:(some-branch) ✗ cd kitchen/modules/module-constant-config/ module-constant-config git:(some-branch) ✗ cargo test
Writing unit tests is one of the best ways to understand the code. Although unit tests are not comprehensive, they provide a first check to verify that the programmer's basic invariants are not violated in the presence of obvious, expected state changes.