24.8 Development Dependencies
Sometimes you need dependencies only for tests (or examples, or benchmarks). These go in the [dev-dependencies] section of Cargo.toml. They are not propagated to other packages that depend on your crate.
One example is pretty_assertions, which replaces the standard assert_eq! and assert_ne! macros with colorized diffs. In Cargo.toml:
[dev-dependencies]
pretty_assertions = "1"
In src/lib.rs:
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq; // Used only in tests.
#[test]
fn test_add() {
assert_eq!(add(2, 3), 5);
}
}