# Does macro-inc/macro Have Unit Tests and Where Are They Located: Complete Guide

> Discover if macro-inc/macro has unit tests and their exact locations. Find tests in respective crate directories and integration tests in crates/integration_tests.

- Repository: [Macro/macro](https://github.com/macro-inc/macro)
- Tags: how-to-guide
- Published: 2026-08-15

---

**Yes, the macro-inc/macro repository maintains an extensive automated test suite with unit tests organized in `tests/` directories within each Rust crate and end-to-end scenarios centralized in `crates/integration_tests`.**

The macro-inc/macro monorepo follows Rust workspace conventions where every component keeps its validation logic separate from production code. Understanding the exact file locations and test architecture enables efficient contribution and debugging across the task deduplication, authentication, and database client systems.

## Unit Test Architecture in the Macro Monorepo

Each crate in the workspace maintains a dedicated `tests/` directory at the crate root, following Rust's standard layout for integration-style test binaries. Tests placed in these directories compile as separate executables that import the crate’s public API, ensuring validation occurs against the same interface exposed to downstream consumers.

The repository employs two primary testing patterns:

- **Unit-style tests**: Using `#[cfg(test)]` modules for internal logic or standalone files in `tests/` for focused component validation
- **Integration binaries**: Separate test executables in `tests/` directories that verify crate boundaries and cross-module interactions

A dedicated `crates/integration_tests` workspace supplements these with end-to-end scenarios spanning multiple services.

## Where to Find Unit Tests by Component

### Task Deduplication Service

The task deduplication logic resides in `crates/task_dedup/` with comprehensive evaluation suites located in `crates/task_dedup/tests/eval/`. The file [`crates/task_dedup/tests/eval/main.rs`](https://github.com/macro-inc/macro/blob/main/crates/task_dedup/tests/eval/main.rs) contains tests that verify deduplication behavior under various concurrency and load conditions.

### Database Client (macro_db_client)

Database interaction and normalization logic is tested in `crates/macro_db_client/tests/`. The file [`crates/macro_db_client/tests/normalize_macro_bot_mention_ids.rs`](https://github.com/macro-inc/macro/blob/main/crates/macro_db_client/tests/normalize_macro_bot_mention_ids.rs) validates Slack mention ID parsing and bot suffix stripping.

### Authentication Service (macro_auth)

Security-critical authentication flows are tested in `crates/macro_auth/tests/`, with [`internal_api_key.rs`](https://github.com/macro-inc/macro/blob/main/internal_api_key.rs) verifying internal API key validation and permission enforcement.

### Client Cache Libraries

The client-side caching system spans multiple crates under `crates/client/cache-*/`, each maintaining `tests/` directories. For instance, [`crates/client/cache-core/tests/engine.rs`](https://github.com/macro-inc/macro/blob/main/crates/client/cache-core/tests/engine.rs) tests the core caching engine supporting WebAssembly, SQLite, and IndexedDB implementations.

### Prompt Composition System

LLM prompt construction and template rendering is validated in `crates/prompt/tests/`, particularly in [`compose.rs`](https://github.com/macro-inc/macro/blob/main/compose.rs), ensuring consistent prompt generation across different model contexts.

### End-to-End Integration Suite

Cross-service integration tests live in `crates/integration_tests/local_e2e/tests/`. The file [`channel_websocket.rs`](https://github.com/macro-inc/macro/blob/main/channel_websocket.rs) validates real-time WebSocket communication channels across the entire service stack.

## Running the macro-inc/macro Test Suite

Execute the complete test suite from the repository root:

```bash
cargo test

```

This command discovers and runs all tests across the workspace, including unit tests, integration binaries, and documentation tests.

To focus on a specific component without compiling the entire monorepo, use the package flag:

```bash
cargo test -p macro_db_client
cargo test -p macro_auth
cargo test -p task_dedup

```

This targeted approach reduces compilation time during iterative development on individual crates.

## Example Unit Test Implementation

The following test from [`crates/macro_db_client/tests/normalize_macro_bot_mention_ids.rs`](https://github.com/macro-inc/macro/blob/main/crates/macro_db_client/tests/normalize_macro_bot_mention_ids.rs) demonstrates the repository's async testing patterns using Tokio:

```rust
#[tokio::test]
async fn test_normalize_macro_bot_mention_ids() {
    // Arrange – a raw mention string that contains a macro‑bot ID
    let raw = "<@U12345|macro-bot>";

    // Act – run the normalisation helper
    let normalized = normalize_macro_bot_mention_ids(&raw).await.unwrap();

    // Assert – the result should be the plain user ID without the bot suffix
    assert_eq!(normalized, "U12345");
}

```

This example follows the Arrange-Act-Assert pattern, utilizing `tokio::test` for async runtime support while verifying that `normalize_macro_bot_mention_ids` correctly processes Slack mention strings.

## Summary

- **Test Location**: Every crate stores tests in a dedicated `tests/` directory at the crate root, keeping validation code separate from `src/` production files
- **Pattern**: Tests compile as distinct binaries that consume public APIs, with `#[cfg(test)]` available for inline unit tests
- **Integration Testing**: End-to-end scenarios reside in `crates/integration_tests/local_e2e/tests/` for multi-service validation
- **Execution**: `cargo test` runs the full suite; `cargo test -p <crate>` isolates specific components
- **Key Files**: Critical suites include [`crates/task_dedup/tests/eval/main.rs`](https://github.com/macro-inc/macro/blob/main/crates/task_dedup/tests/eval/main.rs), [`crates/macro_db_client/tests/normalize_macro_bot_mention_ids.rs`](https://github.com/macro-inc/macro/blob/main/crates/macro_db_client/tests/normalize_macro_bot_mention_ids.rs), [`crates/macro_auth/tests/internal_api_key.rs`](https://github.com/macro-inc/macro/blob/main/crates/macro_auth/tests/internal_api_key.rs), and [`crates/client/cache-core/tests/engine.rs`](https://github.com/macro-inc/macro/blob/main/crates/client/cache-core/tests/engine.rs)

## Frequently Asked Questions

### How do I run tests for a specific crate in macro-inc/macro?

Use Cargo's package selector: `cargo test -p <crate_name>`. For example, `cargo test -p macro_db_client` compiles and executes only the database client's test suite, significantly reducing build times during focused development iterations.

### What testing framework does macro-inc/macro use?

The repository uses Rust's built-in test framework with `#[test]` for synchronous code and `#[tokio::test]` for async functions. The standard library's assertion macros are supplemented by Tokio's async runtime for testing non-blocking database and network operations.

### Are there integration tests in addition to unit tests?

Yes, the repository maintains both unit tests for internal logic and integration tests in `tests/` directories that validate crate boundaries. Additionally, the `crates/integration_tests` workspace contains end-to-end tests exercising multiple services together.

### Where are the end-to-end tests located?

End-to-end tests spanning the full service stack are located in `crates/integration_tests/local_e2e/tests/`, with files like [`channel_websocket.rs`](https://github.com/macro-inc/macro/blob/main/channel_websocket.rs) testing real-time communication flows across integrated components.