← ClaudeAtlas

rust-bevy-test-conventionslisted

Conventions and best practice for writing tests in Rust applications using Bevy ECS. Use when writing or creating tests for Bevy systems, components, resources, or game logic in Rust.
kimgoetzke/coding-agent-configs · ★ 2 · AI & Automation · score 75
Install: claude install-skill kimgoetzke/coding-agent-configs
# Rust Bevy test conventions ## Quick start ```rust #[cfg(test)] mod tests { use super::*; use bevy::prelude::*; use bevy::MinimalPlugins; fn setup() -> App { let mut app = App::new(); app.add_plugins((MinimalPlugins, YourPlugin)); app } #[test] fn system_produces_expected_output() { let mut app = setup(); // Setup: Add resources and entities app.insert_resource(YourResource::default()); // Action: Run the system app.update(); // Assert: Verify results let resource = app.world().resource::<YourResource>(); assert_eq!(resource.value, expected_value); } } ``` ## Testing ECS systems ### Integration-style approach Test Bevy systems using full `App` instances with `MinimalPlugins`: ```rust fn setup() -> App { let mut app = App::new(); app.add_plugins(( MinimalPlugins, YourPlugin, // Add other required plugins )); app } #[test] fn player_input_system_sends_move_message() { let mut app = setup(); // Setup state app.insert_resource(NextState::Pending(AppState::Playing)); app.update(); // Apply state transition // Trigger system behavior app.world_mut().send_event(KeyboardInput { key_code: KeyCode::KeyW, state: ButtonState::Pressed, /* ... */ }); app.update(); // Verify via message resource let messages = app.world().resource::<Messages<MoveMessage>>