> ## Documentation Index
> Fetch the complete documentation index at: https://desme.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Test

> Run cargo test with automatic session capture so you can replay and inspect test execution in the dbgflow browser UI.

`dbgflow test` wraps `cargo test` and captures a session file for every test annotated with `#[dbg_test]`. After the run, it prints the paths of all captured sessions and optionally opens the browser UI focused on the first failing test.

## What it does

**1. Create a timestamped run directory**

dbgflow creates `artifacts/test-sessions/run-<timestamp>/` (or the directory you specify with `--output-dir`) to hold all sessions for this run.

**2. Run cargo test**

dbgflow invokes `cargo test` with `RUST_TEST_THREADS=1` and `DBG_SESSION_DIR` set to the run directory. Each `#[dbg_test]` test writes its session as a `.json` file into that directory.

**3. Report captured sessions**

After the run completes, dbgflow prints the path of every captured session file. If any test failed, it highlights the session for the first failing test.

**4. Serve (optional)**

With `--serve`, dbgflow starts the browser UI loaded with the most relevant session — the first failing test, or the first session if all tests passed. Refreshing the browser re-runs the tests and reloads the session automatically.

> [!NOTE]
>
> dbgflow automatically sets `RUST_TEST_THREADS=1` when running your tests. This ensures tests execute sequentially so that session capture is stable and sessions are not interleaved. You do not need to configure this yourself.

## Flags

**--manifest-path** `path`

Path to the `Cargo.toml` of the project to test. Useful when you are running `dbgflow test` from a directory that is not the project root. Omit this flag to test the project in the current directory.

**--output-dir** `path`

Directory where captured sessions are stored. Defaults to `artifacts/test-sessions`. Each run creates a timestamped subdirectory: `run-<unix-timestamp-ms>/`.

**--serve** `flag`

Start the browser UI after tests complete. Opens the most relevant captured session — the first failing test if any test failed, otherwise the first session. Refreshing the browser re-runs the tests and updates the UI with the new session.

**--port** `u16`

Port for the UI server. Only relevant when `--serve` is set. Defaults to `3000`.

**-- \<cargo args>** `flag`

Any arguments after `--` are passed directly to `cargo test`. Use this to filter tests, select a test binary, or pass any other Cargo test flags.

## Where sessions are saved

Each invocation of `dbgflow test` writes sessions into a timestamped subdirectory:

```
artifacts/test-sessions/
└── run-1714000000000/
    ├── state_flow.json
    ├── process_data.json
    └── integration_test.json
```

Only tests annotated with `#[dbg_test]` produce session files. If no sessions are captured, dbgflow reminds you to add the macro.

## Usage examples

Test the current project:

```bash theme={null}
dbgflow test
```

Test a specific project by Cargo manifest:

```bash theme={null}
dbgflow test --manifest-path /path/to/project/Cargo.toml
```

Open the browser UI immediately after tests complete:

```bash theme={null}
dbgflow test --serve
```

Save sessions to a custom directory:

```bash theme={null}
dbgflow test --output-dir ./my-sessions
```

Run only the library tests:

```bash theme={null}
dbgflow test -- --lib
```

Run a specific integration test:

```bash theme={null}
dbgflow test -- --test integration_tests
```

Combine flags — test a specific project, open the UI, and filter tests:

```bash theme={null}
dbgflow test --manifest-path /path/to/Cargo.toml --serve -- --lib
```

## Live reload with --serve

When you pass `--serve`, the browser UI stays running after the initial test run. Each time you refresh the page, dbgflow re-runs your tests, captures new sessions, and serves the updated results. This gives you a tight feedback loop while you fix failing tests.

> [!WARNING]
>
> Because `--serve` re-runs `cargo test` on every browser refresh, avoid refreshing while you have unsaved changes that could leave your project in an inconsistent state.

## Annotating tests for capture

Only tests marked with `#[dbg_test]` produce session files. Add the macro alongside your existing test attributes:

```rust theme={null}
use dbgflow::prelude::*;

#[dbg_test]
fn my_test() {
    // Execution is captured as a session
}
```

> [!NOTE]
>
> `#[dbg_test]` does not support async tests.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.