Rust testing, data generation and const asserts
--
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 *…