Development dependencies

Sometimes there is a need to have a dependencies for tests (examples, benchmarks) only. Such dependencies are added to Cargo.toml in [dev-dependencies] section. These dependencies are not propagated to other packages which depend on this package.

One such example is using a crate that extends standard assert! macros.
File Cargo.toml:

# standard crate data is left out
pretty_assertions = "0.4.0"

File src/

// externing crate for test-only use
extern crate pretty_assertions;

pub fn add(a: i32, b: i32) -> i32 {
    a + b

mod tests {
    use super::*;

    fn test_add() {
        assert_eq!(add(2, 3), 5);

See Also

Cargo docs on specifying dependencies.