Rust Testing - newgeekorder/TechWiki GitHub Wiki

Out of the box Rust supports testing by annotating a function with

#[test]
fn it_works() {
}

this is picked up by cargo when running

cargo test 

Assert! Macro

  • assert! ( 1 == 1 ); check's for true and can also have it's own custom message:
// assert with a custom message
let x = true;
assert!(x, "x wasn't true!");
assert!(a + b == 30, "a = {}, b = {}", a, b); // with println like syntax 
  • assert_eq!("Hello", "world");