Skip to content

Glossary: System Design Basics in Rust

#[cfg(test)] / #[test]

Also written: #[cfg(test)], #[test]

`#[test]` marks a function as a test, and `#[cfg(test)]` makes a block of code compile only when tests are built. Together they keep test code, such as a TTL cache test with a fake clock, out of the normal program.

Where the book teaches it

Related terms

rustc --testClock (injected clock)