---
title: "Testing Guide"
description: "How to write and run tests for Nexus OS. Unit tests go in the same file as the code they test: Integration tests go in the tests/ directory: Generate coverage reports:"
resource: https://www.aiagents.nexus/docs/manual/contributing/testing
generated: { by: "process:nexus-agent-assets", at: 2026-09-07T09:13:03Z }
status: stable
---

# Testing Guide

How to write and run tests for Nexus OS.

## Running Tests

```bash
# Run all tests
cargo test

# Run a specific test
cargo test test_agent_lifecycle

# Run tests with output
cargo test -- --nocapture

# Run only integration tests
cargo test --test integration
```

## Writing Unit Tests

Unit tests go in the same file as the code they test:

```rust
#[cfg(test)]
mod tests {
    use super::*;
    use tempfile::TempDir;

    #[test]
    fn test_agent_creation() {
        let dir = TempDir::new().unwrap();
        let store = Store::open(dir.path()).unwrap();
        store.create_agent("test", "idle", "test.wasm").unwrap();
        let agents = store.list_agents().unwrap();
        assert_eq!(agents.len(), 1);
        assert_eq!(agents[0].name, "test");
    }
}
```

## Writing Integration Tests

Integration tests go in the `tests/` directory:

```rust
// tests/integration.rs
use std::process::Command;

#[test]
fn test_cli_init() {
    let dir = tempfile::TempDir::new().unwrap();
    let output = Command::new("cargo")
        .args(["run", "--", "init"])
        .current_dir(dir.path())
        .output()
        .unwrap();
    assert!(output.status.success());
}
```

## Test Coverage

Generate coverage reports:

```bash
cargo install cargo-tarpaulin
cargo tarpaulin --out html
open tarpaulin-report.html
```
