Rust testing, data generation and const asserts

Ben McDonald
The Startup
Published in
3 min readJan 29, 2020

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.

// Minimal Rust tests examplefn double(x: u8) -> u8 {
x *

Ben McDonald
The Startup

Rust, bitcoin education, StackOverflow contributor