#bevy-plugin #testing #testing-tools #rstest #insta #assets #fixtures #build #write #test-app

rmv-bevy-testing-tools

Write simple tests for bevy systems, using rstest, insta, and speculoos

19 releases (5 breaking)

0.7.0 May 26, 2025
0.6.2-rc2 Apr 29, 2025
0.5.1 Feb 6, 2025
0.2.0 Jul 23, 2024

#255 in Game dev

Download history 305/week @ 2025-04-13 216/week @ 2025-04-20 483/week @ 2025-04-27 203/week @ 2025-05-04 137/week @ 2025-05-11 27/week @ 2025-05-18 133/week @ 2025-05-25 8/week @ 2025-06-01

1,425 downloads per month

MIT license

33KB
723 lines

rmv-bevy-testing-tools

TestApp

TestApp wraps a bevy::app::App so it can exit cleanly when dropped, and add implements some helpful traits.

# use bevy_app::{App, Plugin, Plugins};
use rstest::{fixture, rstest};
use rmv_bevy_testing_tools::prelude::*;

# struct MySimplePlugin;
# impl Plugin for MySimplePlugin { fn build(&self, _: &mut App) { } }
# struct MyGamePlugin ;
# impl Plugin for MyGamePlugin { fn build(&self, _: &mut App) { } }

#[rstest]
fn test_my_simple_plugin(#[with(MySimplePlugin)] mut test_app: TestApp) {
    // run system tests
}
#[rstest]
fn test_my_game_plugin(#[with(MyGamePlugin)] mut test_app: TestApp) {
    // run systems tests involving assets
}

// setup a reusable fixture with some combination of plugins
#[fixture]
pub fn my_custom_test_app() -> TestApp {
    let mut app = App::new();
    app.add_plugins((
        // add your plugins
    ));
    TestApp(app)
}

// this fixture can take more plugins as argument
#[fixture]
pub fn my_configurable_custom_test_app<P>(
    #[default(())]
    plugins: impl Plugins<P>
) -> TestApp {
    let mut app = App::new();

    app.add_plugins((
        // add your plugins
        plugins,
    ));

    TestApp(app)
}

#[rstest]
fn test_my_configurable_custom_test_app(
    #[from(my_configurable_custom_test_app)]
    #[with((some::SomePlugin, another::SomePlugin))]
    app: TestApp) {
    // ...
}

EventCollector

# use bevy_app::{App, Plugins};
# use bevy_ecs::event::Event;
# use rstest::*;
use speculoos::prelude::*;
use rmv_bevy_testing_tools::prelude::*;

#[derive(Event, Clone, Debug, PartialEq)]
struct MyEvent;

#[rstest]
fn test_events(
    #[with((
        GamePlugin,
        EventCollector::<MyEvent>::new()
    ))]
    mut test_app: TestApp,
) {
    test_app.update();
    let events = test_app.get_collected_events::<MyEvent>();
    assert_that!(&events)
        .named("collected events")
        .is_some()
        .is_equal_to(vec![]);
}

Dependencies

~22–57MB
~1M SLoC