# What Is the Role of the Tests Directory in the Brush Repository?

> Discover the critical role of the tests directory in the Brush repository. Ensure rendering correctness, determinism, and cross-platform stability for desktop, web, and Android.

- Repository: [Arthur Brussee/brush](https://github.com/ArthurBrussee/brush)
- Tags: how-to-guide
- Published: 2026-05-14

---

**The `tests` directories in the brush repository provide a comprehensive safety net that guarantees rendering correctness, determinism, and cross-platform stability across desktop, web, and Android targets.**

The brush repository by ArthurBrussee is a high-performance 3D Gaussian splatting engine written in Rust. Its distributed `tests` directories—located within individual crates and apps—form a layered verification strategy spanning **unit → integration → stress → platform** checks to ensure the engine behaves identically across CPUs, GPUs, WebGPU, and mobile devices.

## Rendering Correctness Verification

At the unit level, tests in [`crates/brush-render/src/tests/mod.rs`](https://github.com/ArthurBrussee/brush/blob/main/crates/brush-render/src/tests/mod.rs) validate that the low-level GPU pipelines initialize correctly and produce valid output. The `renders_at_all` test constructs a minimal scene with eight zero-mean splats, renders a 32×32 image, and asserts that both RGB and alpha channels are black, confirming that the WGPU and CubeCL backends are functional.

```rust
#[wasm_bindgen_test(unsupported = tokio::test)]
async fn renders_at_all() {
    let cam = Camera::new(
        glam::vec3(0.0, 0.0, 0.0),
        glam::Quat::IDENTITY,
        0.5,
        0.5,
        glam::vec2(0.5, 0.5),
    );
    let img_size = glam::uvec2(32, 32);
    let device = brush_cube::test_helpers::test_device().await;
    // … create zero‑mean splats …
    let (output, _aux) = render_splats(splats, &cam, img_size, Vec3::ZERO, None, TextureMode::Float).await;
    // … check that the image is all zeros …
}

```

## Determinism and Invariant Checks

The test suite enforces strict determinism through tests like `render_is_deterministic_on_large_splats` and `hidden_splats_do_not_perturb_render`. These verify that rendering the same scene twice yields pixel-identical results and that invisible splats never affect the output, preventing subtle race conditions or incorrect compact-gather ordering that would break reproducible training pipelines.

```rust
#[wasm_bindgen_test(unsupported = tokio::test)]
async fn render_is_deterministic_on_large_splats() {
    let cam = Camera::new(...);
    let img_size = glam::uvec2(256, 256);
    let device = brush_cube::test_helpers::test_device().await;
    let scene = rng_scene(20_000, 2.0, (0.5, 3.0), (-1.0, 2.0), 0xA11CE);
    let a = render_scene(&scene, &cam, img_size, &device).await;
    let b = render_scene(&scene, &cam, img_size, &device).await;
    assert_eq!(max_abs_diff(&a, &b), 0.0);
}

```

## Stress Testing and Edge Cases

Stress tests push the engine to its limits with massive-scale scenes. Tests such as `mega_stress_fullscreen_splats` and `renders_many_large_splats_stress` validate the renderer against 30 million to 200 million splats, ensuring every tile receives contributions and that no NaNs or infinities appear. These tests detect memory-pressure, overflow, or tile-dropping bugs that only surface under real-world workloads.

## Loss Function Validation

The [`brush-loss/tests/reference.rs`](https://github.com/ArthurBrussee/brush/blob/main/brush-loss/tests/reference.rs) file validates the mathematical correctness of the training loss. The `image_loss_backward_runs` test checks SSIM/L1 loss values, gradient computation, and correct handling of 4-channel predictions, ensuring gradients remain finite—essential for the machine-learning training loop.

```rust
#[wasm_bindgen_test(unsupported = tokio::test)]
async fn image_loss_backward_runs() {
    let device = brush_cube::test_helpers::test_device().await;
    let (h, w) = (32, 48);
    let pred = pred_from_bytes(...).require_grad();
    let gt = gt_packed_from_bytes(...);
    let map = image_loss(pred, gt, ImageLossConfig { l1_weight: 0.8, ssim_weight: -0.2, ..Default::default() });
    let _grads = map.mean().backward(); // verifies gradient flow
}

```

## Integration and Platform Compatibility

Integration tests ensure the public API works for downstream consumers. The [`apps/brush-c/tests/integration.rs`](https://github.com/ArthurBrussee/brush/blob/main/apps/brush-c/tests/integration.rs) file validates C-API bindings, confirming the library can be linked from external languages like C++ or Python. The GitHub Actions workflow in [`.github/workflows/ci.yml`](https://github.com/ArthurBrussee/brush/blob/main/.github/workflows/ci.yml) runs `cargo test --all` on each push, aborting the build if any test fails and guaranteeing every change is vetted automatically.

## Key Test Files in the Repository

| Path | Purpose |
|------|---------|
| [`crates/brush-render/src/tests/mod.rs`](https://github.com/ArthurBrussee/brush/blob/main/crates/brush-render/src/tests/mod.rs) | Core rendering unit tests, determinism, stress, and edge-case checks |
| [`crates/brush-loss/tests/reference.rs`](https://github.com/ArthurBrussee/brush/blob/main/crates/brush-loss/tests/reference.rs) | Validation of SSIM/L1 loss implementation and gradient computation |
| [`crates/brush-bench-test/tests/integration.rs`](https://github.com/ArthurBrussee/brush/blob/main/crates/brush-bench-test/tests/integration.rs) | End-to-end bench-style integration tests for training pipelines |
| [`apps/brush-c/tests/integration.rs`](https://github.com/ArthurBrussee/brush/blob/main/apps/brush-c/tests/integration.rs) | C-API integration tests for cross-language usage |
| [`.github/workflows/ci.yml`](https://github.com/ArthurBrussee/brush/blob/main/.github/workflows/ci.yml) | CI configuration enforcing the full test suite on every commit |

## Running the Test Suite

Execute the full verification suite from the repository root using Cargo:

```bash
cargo test --all

```

To run tests for a specific crate only:

```bash
cargo test -p brush-render

```

## Summary

- **Layered verification**: The tests directory implements a strategy covering unit tests, integration tests, stress tests, and platform compatibility checks.
- **Determinism guarantees**: Tests like `render_is_deterministic_on_large_splats` ensure reproducible results across runs.
- **Performance validation**: Stress tests with up to 200 million splats verify stability under extreme workloads.
- **Cross-platform safety**: C-API tests and `wasm_bindgen_test` attributes ensure correctness on desktop, web, and mobile.
- **CI enforcement**: The [`.github/workflows/ci.yml`](https://github.com/ArthurBrussee/brush/blob/main/.github/workflows/ci.yml) configuration automatically blocks merges that break the build.

## Frequently Asked Questions

### What types of tests are included in the brush repository?

The repository contains four primary categories: **unit tests** for rendering correctness (e.g., `renders_at_all`), **determinism tests** to ensure identical output across runs, **stress tests** that validate behavior with 30M–200M splats, and **integration tests** for C-API bindings and training pipelines.

### How does the brush repository ensure rendering is deterministic?

The `render_is_deterministic_on_large_splats` test in [`crates/brush-render/src/tests/mod.rs`](https://github.com/ArthurBrussee/brush/blob/main/crates/brush-render/src/tests/mod.rs) renders the same random scene twice and asserts that the maximum absolute difference between outputs is exactly zero. Additional tests like `hidden_splats_do_not_perturb_render` verify that invisible geometry never affects the output, preventing nondeterministic behavior caused by incorrect tile sorting or race conditions.

### Where are the C API tests located in the brush repository?

The C API integration tests reside in [`apps/brush-c/tests/integration.rs`](https://github.com/ArthurBrussee/brush/blob/main/apps/brush-c/tests/integration.rs). These tests validate that the library can be correctly linked and called from C code, ensuring the public FFI interface works for downstream consumers using languages other than Rust.

### How do I run the brush tests locally on my machine?

Navigate to the repository root and execute `cargo test --all` to run the entire suite across all crates. For platform-specific testing (such as WebAssembly), use `wasm-pack test` with the appropriate target flags, as the test suite utilizes `wasm_bindgen_test` attributes for browser compatibility.