--- type: testing title: Unit tests description: Overview of the in-module unit test suites in src/*.rs, what each one covers and how to run them. tags: [testing, cargo, unit-tests] verified: - by: openwiki/0.7.2 at: 2026-10-19T18:58:46.219Z sources: - id: openwiki-source-651d1fb6c9e49916a916ab51 resource: repo://Cargo.toml - id: openwiki-source-1b05507d7085e8e99a9b64f1 resource: repo://src/ai.rs - id: openwiki-source-9fec9d1af408501c9c455161 resource: repo://src/app.rs - id: openwiki-source-043e6252badc57a1ee6bfb48 resource: repo://src/autoreply.rs - id: openwiki-source-2a737474d86fc75cc9d9694f resource: repo://src/config.rs - id: openwiki-source-ce0c4ea8cd3b15431fa691ce resource: repo://src/history.rs - id: openwiki-source-6bddea306b9b87f180f1fc02 resource: repo://src/ui.rs - id: openwiki-source-7ea5eac45e5030178a6ea05b resource: repo://src/whatsapp.rs generated: { by: "claude-code", at: "2026-10-19T18:58:46.219Z" } --- # Unit tests All tests are plain Rust unit tests in `#[cfg(test)] mod tests` blocks at the bottom of each source file. There are no integration tests, no `[dev-dependencies]` (`Cargo.toml` only has `[dependencies]`) and no test touches the network or a real WhatsApp session. ## Running ```sh cargo test # whole suite cargo test autoreply:: # one module cargo test should_reply_false # by name filter ``` ## Suites | Module | Tests | Location | Covers | |---|---|---|---| | `autoreply` | 41 | `src/autoreply.rs:282+` | private/self-chat detection, every `ReplyGate::should_reply` rule (disabled, own messages, non-private chats, backlog, blank/placeholder text, cooldown per chat), `build_turns` roles, context truncation, voice-note and image instructions | | `config` | 18 | `src/config.rs:236+` | defaults, trimming, multiline prompt, base URL normalisation, `Debug` masking, DB paths, BOM/CRLF, non-leaking parse errors, missing/invalid/unreadable files | | `ai` | 15 | `src/ai.rs:320+` | request and vision body shapes, image validation limits, `Debug` redaction, reply parsing, endpoint construction, truncation | | `whatsapp` | 21 | `src/whatsapp.rs:945+` | message rendering and placeholders, captions, image references, silent messages, JID device suffix, push-name filtering | | `history` | 11 | `src/history.rs:392+` | dedupe by message id, ordering and limits, chat name fallbacks, autoreply flags, contacts, on-disk open | | `ui` | 11 | `src/ui.rs:508+` | sender labels, clock time, QR text, wrapping, visible lines, input tail, title, selection clamp | | `app` | 10 | `src/app.rs:762+` | autoreply enable rules, vision applicability, error combining, selection and toggle helpers, AltGr handling | Total: 127 `#[test]` functions. ## Test isolation - History tests use `History::open_in_memory()` (only compiled for tests, `src/history.rs:75-81`); the on-disk test writes under `std::env::temp_dir()` in a per-process directory (`src/history.rs:579-593`). - AI tests check request bodies and parsing without sending requests. Pages with module details: [AI autoreply](../workflows/ai-autoreply.md), [Configuration](../operations/configuration-and-data.md), [AI client](../integrations/ai-client.md), [WhatsApp client](../integrations/whatsapp-client.md), [History store](../concepts/history-store.md), [Terminal UI](../architecture/terminal-ui.md), [Application state](../architecture/app-state.md).