O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Annotations

As you saw earlier, the test code can be included in the same file as the implementation code. Functions are marked as test functions by the #[test] annotation:

// test.rs #[test] fn test_case() {     assert!(true) } 

The compiler ignores the test functions totally unless it's told to build in test mode. This can be achieved by using the --test parameter with rustc and executed by running the binary:

However, since Cargo has support for tests, this is usually done more easily via Cargo by commanding cargo test (which builds and runs the tests).

When your tests grow in complexity, it may be useful to isolate the test code from the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required