Rust testing, data generation and const asserts

Ben McDonald
Jan 29, 2020 · 3 min read

Basic Rust test example

Luckily getting starting with testing Rust code is reasonably straightforward and no external libraries are needed. cargo test will run all test code in a Rust project. Test code is identified with the code attributes #[cfg(test)] and #[test]. For the placement of the test code, units tests are added at the end of a source code file and integration tests can be placed in their own tests directory.

fn (x: u8) -> u8 {
x *