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.
The following modules in the kitchen have partial unit test coverage
To run the tests, clone the repo
$ git clone https://github.com/substrate-developer-hub/recipes
Enter the path to the pallet to be tested
$ cd pallets/<some-module>
For example, to test
constant-config, used in
$ cd pallets/constant-config/ $ 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.