New Rustacean

e007: Testify

New Rustacean

Notes

All about testing in Rust! In order, we take a look at:

  • Why you need tests.
  • Unit tests in other (dynamically-typed) languages vs. in Rust.
  • How to write unit tests in Rust.
  • How and why to write integration tests in Rust.
  • How and why to use benchmarks in Rust.

The detailed code samples for this episode are heavy on showing; because of the nature of test functions, you will be best off just reading the source rather than leaning heavily on the descriptions generated by rustdoc. (The descriptions are still there, but they’re much less useful than they have been in previous episodes.) In particular, the test module here is excluded because of the use of the #[cfg(test)] attribute marker on it.

Because we are using the feature-gated benchmarking functionality, the show notes “library” can now only be compiled with the Rust nightly (as of 1.5, the version current as this episode is produced).

One thing that isn’t necessarily obvious from reading the test documentation in the Rust book and Rust reference: the extern crate test statement needs to be not in this module, but at the module (lib.rs) which defines the library/crate; in this case, show_notes/lib.rs.

Sponsors

  • Chris Palmer
  • Derek Morr
  • Luca Schmid
  • Micael Bergeron
  • Ralph Giles (“rillian”)
  • reddraggone9
  • William Roe

Become a sponsor

Follow

Next Episodes

New Rustacean

Bonus 2: Legacy Code @ New Rustacean

📆 2015-12-06 19:23 / 00:09:41


New Rustacean

Bonus 1: Polyglot Programming Promises and Perils @ New Rustacean

📆 2015-11-25 17:27 / 00:08:28


New Rustacean

e006: Modularize this! @ New Rustacean

📆 2015-11-16 16:36 / 00:18:22


New Rustacean

e005: Allocate it where? @ New Rustacean

📆 2015-11-08 21:15 / 00:18:30


New Rustacean

e004: Functionalized @ New Rustacean

📆 2015-10-30 03:45 / 00:17:07