You can use the assert! macro to assert certain conditions in your test. This macro invokes panic!() and fails the test if the expression inside evaluates to false.
Using {} will print the value, and using {:?} will print the value plus its type.
Using {:?} will also allow you to print values that do not have the Display trait implemented but do have the Debug trait. Alternatively you can use the dbg! macro to print these types of variables.
To print more complex types that don't have it already, you can implement your own formatted display method with the fmt module from the Rust standard library.
use std::fmt;structPoint { x:u64, y:u64,}// add print functionality with the fmt module impl fmt::DisplayforPoint {fnfmt(&self, f:&mut fmt::Formatter) -> fmt::Result {write!(f, "value of x: {}, value of y: {}", self.x, self.y) }}let p =Point {x:1, y:2};println!("POINT: {}", p);
You can run your tests to see if they pass or fail with
cargo test
Outputs will be hidden if the test passes. If you want to see outputs printed from your tests regardless of whether they pass or fail, use the nocapture flag.