Tutorial by Examples

fn to_test(output: bool) -> bool { output } #[cfg(test)] // The module is only compiled when testing. mod test { use super::to_test; // This function is a test function. It will be executed and // the test will succeed if the function exits cleanly. #[test] fn...
lib.rs: pub fn to_test(output: bool) -> bool { output } Each file in the tests/ folder is compiled as single crate. tests/integration_test.rs extern crate test_lib; use test_lib::to_test; #[test] fn test_to_test(){ assert_eq!(to_test(true), true); }
With benchmark tests you can test and measure the speed of the code, however benchmark tests are still unstable. To enable benchmarks in your cargo project you need nightly rust, put your integration benchmark tests to the benches/ folder in the root of your Cargo project, and run cargo bench. Exam...

Page 1 of 1