Hazel

Testing

How to write and run tests in the engine workspace: natively while you iterate, in the container when a result must match CI, and what CI itself runs.

Running tests natively

Per-crate tests link and run natively on every desktop platform, Windows included. This is the fast way to iterate, an order of magnitude quicker than a container round trip:

cargo test --profile dist -p renzora_physics
cargo test --profile dist -p renzora_ember parse_templates   # one test, by substring
cargo test --profile dist -p renzora_net -- --nocapture       # show println! output

Always pass --profile dist. A bare cargo test builds the dev profile and a second full artefact tree, which this workspace is too large for.

Test the crate you are working on. For the whole suite, use the container (below) rather than a native --workspace run: a workspace test build is its own large set of artefacts that nothing else on your machine reuses.

Running tests the way CI does

renzora test            # the workspace suite, in the Linux container
renzora test [args]     # arguments are passed on

renzora test runs in the pinned toolchain container, so the suite sees the exact rustc and system libraries CI uses, and nothing it builds lands in your host's target/. The renzora CLI is installed separately; see Cross-Compiling.

What CI runs

.github/workflows/test.yml runs on every push and pull request to main. Every job runs inside the shared base image ghcr.io/renzora/base:latest, which carries rustc and the Linux development libraries, so the runner installs nothing.

JobWhat it checks
synccargo renzora sync --check: the committed plugin lists match what the generator would write
versionsscripts/check-versions.sh: every copy of the engine version agrees (see Releases)
testcargo renzora check-bevy, then cargo test --workspace --no-fail-fast --exclude bevy_hui
wasmcargo check of the web runtime and the web editor for wasm32-unknown-unknown
gputhe render-touching crates' tests on Mesa's software Vulkan, with RENZORA_GPU_TESTS=1
clippyclippy over the workspace with -D warnings, then over xtask and tools/updater

The clippy job's workspace command:

cargo clippy --workspace --no-deps --exclude bevy_hui -- \
    -D warnings \
    -A clippy::too_many_arguments \
    -A clippy::type_complexity

bevy_hui is the one vendored crate that is still a workspace member; Bevy itself and the other vendored subtrees are excluded from the workspace entirely, so --workspace never reaches them. New first-party crates are covered automatically, because the member globs pick them up.

--no-fail-fast makes the test job report every failing crate rather than stopping at the first. CI builds without debug info or incremental artefacts to fit a runner's disk.

Unit tests

Unit tests live in a #[cfg(test)] module in the file they cover:

fn clamp_health(current: f32, max: f32) -> f32 {
    current.min(max)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn health_clamps_to_max() {
        assert_eq!(clamp_health(150.0, 100.0), 100.0);
    }

    #[test]
    fn health_below_max_is_unchanged() {
        assert_eq!(clamp_health(40.0, 100.0), 40.0);
    }
}

Testing systems

Most engine logic is a Bevy system, so the usual pattern is: build an App, add the system, run a frame with app.update(), read the result back out of the World.

use bevy::prelude::*;

#[derive(Component)]
struct Health(f32);

fn regenerate(mut query: Query<&mut Health>) {
    for mut health in &mut query {
        health.0 += 1.0;
    }
}

#[test]
fn health_regenerates_each_frame() {
    let mut app = App::new();
    app.add_plugins(MinimalPlugins);
    app.add_systems(Update, regenerate);

    let entity = app.world_mut().spawn(Health(50.0)).id();
    app.update();

    assert_eq!(app.world().get::<Health>(entity).unwrap().0, 51.0);
}

For pure ECS logic you can skip the App and drive a World directly with world.spawn(...) and world.query::<...>().

The test harness

renzora_test_harness builds the App for you. Add it as a dev-dependency and pick the cheapest tier the code under test can run in:

[dev-dependencies]
renzora_test_harness = { path = "../renzora_test_harness" }
BuilderWhat you getUse it for
minimal_app()MinimalPlugins, assets, transforms, diagnosticspure logic, one system, data transforms; runs in milliseconds
headless_app()full DefaultPlugins with no graphics backend, already finish()edresources, messages, asset loaders, anything that needs the full plugin set but no GPU
headless_app_with(|app| ...)the same, with a chance to add plugins before finish()testing a plugin under the headless set
headless_app_with_assets(root)headless_app() with the asset root at a path relative to the crateloading fixtures from tests/fixtures/
gpu_app()full DefaultPlugins with a real adapter, or Nonerender-graph nodes, pipelines, materials, post-process

headless_app() has already called finish(), and Bevy refuses plugins after that. To test your own plugin under the headless set, add it inside headless_app_with:

use renzora_test_harness::{headless_app_with, pump};

#[test]
fn the_plugin_inserts_its_settings() {
    let mut app = headless_app_with(|app| {
        app.add_plugins(MyPlugin);
    });
    pump(&mut app, 1);
    assert!(app.world().get_resource::<MySettings>().is_some());
}

headless_app() is not a mock: it is the dedicated server's configuration (no graphics backend, so Bevy skips renderer initialisation), minus LogPlugin and WinitPlugin, which cannot run more than once per process or without a display. A plugin that panics under it has a real bug in its headless path.

Three helpers matter more than they look:

  • with_manual_time(&mut app, hz). Without it, wall-clock time barely advances between app.update() calls and FixedUpdate may never run, so a physics or network test asserts on a simulation that never happened, and passes whenever the assertion holds for the initial state. Each update then advances the clock by 1/hz seconds. The first update still has a delta of zero, so pump at least twice before asserting that something time-scaled moved.
  • pump_until(&mut app, max_frames, "what", |app| ...). Asset loads, task completions and command application span frames, so "load it and assert" is a race. This waits for a condition and panics with your description if it never holds, rather than letting a confusing downstream assertion fail.
  • pump(&mut app, n). Run exactly n frames.

GPU-backed tests

gpu_app() returns None unless RENZORA_GPU_TESTS=1 is set, and a test treats that as a skip:

#[test]
fn the_pass_writes_its_target() {
    let Some(mut app) = renzora_test_harness::gpu_app() else { return };
    // ...
}

An environment opt-in rather than a probe, because Bevy requests its adapter inside Plugin::finish, and on a machine without one that is a panic deep in renderer setup with no way to ask first. CI's gpu job sets the variable after installing Mesa's software Vulkan; set it locally to run the same tests on your own GPU.

Fixed-timestep systems

Physics and anything else on the fixed-timestep schedule needs manual time, and the plugins' finish and cleanup steps, which a real app's runner calls and a bare app.update() loop does not. The physics conformance suite's physics_app (crates/renzora_physics/tests/conformance/harness.rs) builds its app, then calls app.finish() and app.cleanup() before returning it.

Integration tests

Tests that exercise a crate's public API from outside go in crates/<crate>/tests/*.rs. Some worth reading before you write one:

TestWhat it proves
crates/renzora_native_plugin/tests/load_plugin.rsa plugin compiles against the staged SDK and loads into a real App: the whole install path, end to end
crates/renzora_net/tests/round_trip.rsthe HTTP request chain end to end against a fake backend, so there are no sockets to flake
crates/renzora_physics/tests/conformance/the physics API, written only against the contract's components, so any backend can be held to it
crates/renzora_physics/tests/accuracy.rsthe physics engine against closed-form mechanics
crates/renzora_bsn/tests/raw_roundtrip.rsthe scene format survives a serialize and deserialize round trip
crates/renzora_ember/tests/parse_templates.rsevery shipped UI template parses, without a GPU
crates/renzora_ember/tests/inspector_writeback.rsinspector edits write back into the template source correctly

Installed plugins live outside this repository, so CI cannot test them. load_plugin.rs stands in for them by taking the same path every installed plugin takes, and every nightly compiles the published plugins against its own SDK (see Releases).

Shaking out system-ordering bugs

Two systems with no ordering between them run in whatever order Bevy's schedule builder picks, and it picks the same one every launch. A system that secretly depends on running after another works every time, until an unrelated change moves it.

Launch with RENZORA_SHUFFLE_SEED set to any whole number and every schedule, the render world's included, picks a different valid order:

RENZORA_SHUFFLE_SEED=7 ./renzora
$env:RENZORA_SHUFFLE_SEED = 7; .\renzora.exe

Every before, after and chain is still honoured; only the freedom left over is shuffled. If something breaks under one seed and not another, it is missing an ordering constraint, and the same seed reproduces it every time. With the variable unset, nothing changes.

Coverage

Line coverage is measured with cargo-llvm-cov and gated by a per-crate ratchet in coverage-floors.txt.

rustup component add llvm-tools-preview
cargo install cargo-llvm-cov --locked

cargo renzora coverage                 # measure the workspace, print the table worst-first
cargo renzora coverage --check         # fail if any crate fell below its floor
cargo renzora coverage --bless         # record the current numbers as the new floors
cargo renzora coverage --report-only   # re-read the last run's lcov without rebuilding
cargo renzora coverage --open          # also open the HTML report

The gate is per crate, never one workspace number. Testability varies by orders of magnitude across the workspace: an input action map is pure data, a render pass cannot run without a GPU. One global threshold would have to be set low enough for the worst crate, so it would gate nothing, and a well-tested crate's gains would silently pay for a regression elsewhere. The rule is only never go down, per crate. Raise the floors with --bless in the same commit that adds the tests, and never lower one to make CI green.

Bless from a Linux measurement. Coverage is not identical across platforms (a #[cfg(windows)] branch is an uncovered line on Linux), so floors are written 1.5 points below the measured value, and blessing from the platform CI measures on removes the skew. Take CI's numbers:

gh run download <run-id> -n coverage -D target/coverage
cargo renzora coverage --report-only --bless

--report-only re-reads target/coverage/workspace.lcov without compiling anything.

Things to know before you trust a number:

  • Coverage is measured on the dist profile. opt-level = 2 merges and inlines before instrumentation lands, so the percentages run slightly optimistic. They are a trend line and a regression gate, not proof of exhaustiveness.
  • dist strips symbols, and llvm-cov resolves coverage records through the symbol table, so an unmodified dist build reports every crate at 0% with no error. cargo renzora coverage forces CARGO_PROFILE_DIST_STRIP=none; a hand-rolled cargo llvm-cov run must too.
  • Instrumentation changes every crate's fingerprint, so cargo-llvm-cov keeps its own full artefact tree in target/llvm-cov-target/. This is the one deliberate exception to the one-profile rule. It is disposable: delete it when you need the disk back.
  • Run it on an otherwise idle machine. It is a second full compile of the workspace. Alongside another build it can exhaust memory, and that, like a full disk, surfaces as compile errors in crates nobody touched rather than as an out-of-memory message.

.github/workflows/coverage.yml runs weekly and on demand, not on pull requests: a runner has about 20 GB of usable disk and a coverage run is a second full artefact tree. It uploads the lcov and HTML report as the coverage artifact and enforces the floors.

Notes

  • There is no benchmark suite; no first-party crate has a benches/ directory.
  • Everything except the opt-in GPU tier runs headless, which is what lets the suite run in a container.