Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

test-bevy-systems

/test-bevy-systems

Pisze testy gry w Bevy bez okna: aplikacje z MinimalPlugins, pojedyncze systemy, wiadomości, obserwatory i przejścia stanów oraz cargo-nextest.

Licencja
MIT
Ostatnia zmiana repozytorium
23.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
2
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 23.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pisze testy gry w Bevy bez okna: aplikacje z MinimalPlugins, pojedyncze systemy, wiadomości, obserwatory i przejścia stanów oraz cargo-nextest.

Oryginalny opis (EN)

Use when writing or fixing tests for a Bevy game — headless App/World tests with MinimalPlugins, running one system, asserting messages, observers and state transitions, deterministic time, ordering checks, property tests, and cargo-nextest in CI.

Jak działa

  1. 1. Audit current state (change nothing)
  2. 2. Decide what to do
  3. 3. Detect track
  4. 4. Install only what's missing
  5. 5. Generate the seams
  6. 6. Wire it
  7. 7. Verify
Sekcje z nagłówków SKILL.md, w oryginale · 110 linii, 554 słów
Podgląd SKILL.md
---
name: test-bevy-systems
description: Use when writing or fixing tests for a Bevy game — headless App/World tests with MinimalPlugins, running one system, asserting messages, observers and state transitions, deterministic time, ordering checks, property tests, and cargo-nextest in CI.
---

# Test Bevy Systems

Bevy 0.20, `cargo-nextest`. Rationale and pitfalls: [testing-patterns.md](testing-patterns.md). Versions: [stack-versions](../_shared/stack-versions.md).

## 1. Audit current state (change nothing)

```bash
cat .claude/stack-profile.md 2>/dev/null                   # tests.layout, task_runner, ci
ls tests/ .config/nextest.toml 2>/dev/null; ls src/lib.rs
grep -rln "#\[test\]" src/ tests/ | head
grep -rnE "DefaultPlugins|WinitPlugin|RenderPlugin" tests/ src/**/tests* 2>/dev/null   # windowed tests: replace
grep -n "nextest\|cargo test" justfile Makefile mise.toml .github/workflows/*.yml 2>/dev/null
cargo nextest --version; grep -n "proptest" Cargo.toml
```

`tests.layout: tests-dir` (default): integration tests in `tests/`, one file per feature. `colocated`: unit tests in `#[cfg(test)] mod tests` next to the plugin; keep integration tests in `tests/` anyway.
No `src/lib.rs` → the game cannot be tested; run [scaffold-bevy-game](../scaffold-bevy-game/SKILL.md) step 5 first.

## 2. Decide what to do
- No tests → add the harness (step 5) and one test per plugin: its main state change.
- Tests exist but use `DefaultPlugins` → switch to `MinimalPlugins` (windowed tests need a GPU and break CI).
- Harness, per-feature tests, nextest in CI present → "already in place", stop.

## 3. Detect track
- **Pure logic (damage, scoring, movement math):** `run_system_once` on a bare `World`; no `App`.
- **Cross-system behavior (messages, observers, states):** `App` with `MinimalPlugins + StatesPlugin + the plugin under test`.
- **Time-dependent:** add `TimeUpdateStrategy::ManualDuration`.
- **Assets:** add `AssetPlugin::default()` and only the loaders you test.
- **Input-space tests (any number, any order):** `proptest`.

## 4. Install only what's missing

```bash
cargo install cargo-nextest --locked          # local; CI uses taiki-e/install-action
```
```toml
# Cargo.toml — only if used
[dev-dependencies]
proptest = "1.11"
bevy = { version = "0.20", default-features = false, features = ["debug"] }   # enables schedule shuffling in tests only
```

## 5. Generate the seams

One helper per test file builds the smallest app that can run the feature:

```rust
fn test_app() -> App {
    let mut app = App::new();
    app.add_plugins((MinimalPlugins, StatesPlugin, CorePlugin, PlayerPlugin));
    app
}
```

Run one system on a bare world:

```rust
let mut world = World::new();
let target = world.spawn(Health(30.0)).id();
world.init_resource::<Messages<Damage>>();
world.write_message(Damage { target, amount: 10.0 });
world.run_system_once(apply_damage).unwrap();          // use bevy::ecs::system::RunSystemOnce
assert_eq!(world.get::<Health>(target), Some(&Health(20.0)));
```

Drive a state transition, then assert (state transitions run before `Update` inside the same `update()`):

```rust
app.world_mut().resource_mut::<NextState<Screen>>().set(Screen::Playing);
app.update();                                           // transition + OnEnter + Update in the new state
assert_eq!(app.world_mut().query::<&Player>().iter(app.world()).count(), 1);
```

Deterministic time:

```rust
app.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_millis(500)));
app.update(); // first update only initialises the clock: delta is 0
app.update(); // now delta == 500 ms
```

Observers, messages and ordering checks: copy from [testing-patterns.md](testing-patterns.md).

`.config/nextest.toml`:

```toml
[profile.ci]
fail-fast = false
retries = 0
slow-timeout = { period = "30s", terminate-after = 4 }
```

## 6. Wire it
- Task runner (from the profile; `just` shown): `test: cargo nextest run` and `cargo test --doc` (nextest does not run doctests).
- CI: `taiki-e/install-action@v2` with `tool: cargo-nextest`, then `cargo nextest run --profile ci` and `cargo test --doc` (full workflow: [scaffold-patterns.md](../scaffold-bevy-game/scaffold-patterns.md#rule-ci-mirrors-just-check)).
- Each new plugin lands with a test file `tests/<feature>.rs` in the same change.
- No `thread::sleep`. Advance with `app.update()` and manual time. Asset waits are bounded loops.

## 7. Verify

```bash
cargo nextest run --profile ci
cargo test --doc
```

Expected: every test passes in well under a second per test and no window opens. Break a system on purpose (flip a sign): its test must fail. Run with `--no-fail-fast` in a pipeline that has retries off to confirm no flakiness.

Contracts: [engineering principles](../../core/_shared/engineering-principles.md) (tests at the boundary that pays).
Pliki w paczce (2)
  • SKILL.md 5 KB
  • testing-patterns.md 9 KB

Wersje

W bazie nie ma innych skilli o nazwie test-bevy-systems.

Migawka bazy z 13.11.2026 · wersja paczki 25ad6446e225 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 1 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100bevy-testing-patterns
    Testuje logikę harmonogramu Bevy przez cargo test, MinimalPlugins i app.update(), w testach jednostkowych systemów, zasobów i kolejności .chain().
  • 100bevy-project-foundations
    Ustala przed systemami rozgrywki wersję crate'a Bevy 0.20, opt-level profilu deweloperskiego i granice pluginów, dla aplikacji okienkowej lub headless.
  • 100cargo-nextest
    Uruchamia testy Rust przez cargo-nextest z równoległym wykonaniem i filtrowaniem, konfiguruje CI i diagnozuje testy niestabilne lub wolne.
  • 100scaffold-bevy-game
    Zakłada nowy projekt gry w Bevy albo naprawia powolną kompilację: crate lib i bin, szybkie buildy dev, CI z clippy i nextest oraz wariant wasm.
  • 100structure-bevy-app
    Pomaga dodawać funkcje do gry w Bevy lub porządkować ją: wtyczki na funkcję, stany aplikacji, kolejność systemów i konflikty zapytań.
  • 100bevy-cargo-features
    Dobiera flagi Cargo Bevy 0.19, takie jak 2d, 3d, ui i audio, składa zestawy renderowania, buduje tryb headless i diagnozuje brak UI, dźwięku lub wejścia po wyłączeniu domyślnych funkcji.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.