#Test panicked (Camera query)

1 messages · Page 1 of 1 (latest)

carmine parrot
#

Hello people, I am trying to implement a test for my Camera, I have the following code:

pub fn test_update_camera() {
    let mut app = App::new();

    app.add_plugins(MinimalPlugins);

    /* PLAYER */
    app.insert_resource(Assets::<ColorMaterial>::default());
    app.insert_resource(Assets::<Mesh>::default());
    app.insert_resource(ButtonInput::<KeyCode>::default());

    /* GLOBAL RESOURCES */
    app.insert_resource(CameraScale(0.5));
    app.insert_resource(CameraDecayRate(10.));
    app.insert_resource(GridTileSize(32.));
    app.insert_resource(GridLdtkAlignment(16.));

    app.add_systems(Startup, (startup_camera, startup_player));
    app.update();

    app.add_systems(Update, (
            update_camera, 
            (update_player_input_move, update_player_move).chain()
        )
    );
    app.update();

    /* enough time to move the camera to character */
    for _ in 0..30000 {
        app.update();
    }

    let camera_query = app.world_mut().query::<&Transform>().single(app.world());
    assert!(camera_query.is_ok(), "when camera spawned should return only one entity");

    let camera_trasform = camera_query.unwrap();
    let is_x_initial_position = camera_trasform.translation.x >= 16. && camera_trasform.translation.x < 17.;
    assert!(is_x_initial_position, "when camera moves to player should return correct translation.x");

    let is_y_initial_position = camera_trasform.translation.y >= 16. && camera_trasform.translation.y < 17.;
    assert!(is_y_initial_position, "when camera moves to player should return correct translation.y");
    assert_eq!(camera_trasform.translation.z, 0., "when camera moves should keep the translation.z");
}
#

When I try to execute the test case, it returns:

failures:

---- systems::camera_test::test_update_camera stdout ----

thread 'systems::camera_test::test_update_camera' panicked at tests/systems/camera_test.rs:65:5:
when camera spawned should return only one entity
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

failures:
    systems::camera_test::test_update_camera

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.74s

error: test failed, to rerun pass `--test tests`

I am new to rust and maybe is something I am missing. Do you have any idea why is it happening?