Replies: 1 comment
-
I looks like there is a workaround of dropping cargo test in favor of nextest: First we adapt norenderer (there are 2 examples that at first sound interesting, but headless relies on disabiling a whole feature, and headless renderer is 500LoC about image rendering) updated codeuse bevy::{
prelude::*,
render::{RenderPlugin, settings::WgpuSettings},
winit::{WakeUp, WinitPlugin},
};
fn spawn_map(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let dummy_mesh = meshes.add(Cuboid::from_length(1.0));
let dummy_material = materials.add(StandardMaterial::default());
commands.spawn((
Mesh3d(dummy_mesh),
MeshMaterial3d(dummy_material),
Transform::from_xyz(0.0, 1.0, 0.0),
));
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, spawn_map)
.run();
}
#[test]
fn test_defaults_but_null_renderer() {
let mut winit = WinitPlugin::<WakeUp>::default();
winit.run_on_any_thread = true;
let mut app = App::new();
app.add_plugins(
DefaultPlugins
.set(RenderPlugin {
render_creation: WgpuSettings {
backends: None,
..default()
}
.into(),
..default()
})
.set(winit),
);
app.add_systems(Startup, spawn_map);
app.update();
let mut q = app.world_mut().query_filtered::<&Transform, With<Mesh3d>>();
let only = q.single(&app.world());
assert_eq!(only.unwrap().translation.y, 1.0);
}
#[test]
fn run_test_again() {
test_defaults_but_null_renderer();
} The problem with it is default plugin and winit can't be reinitialized. even if we'll disable logplugin, winit itself will complain about event loop recreationrunning 2 tests
2025-09-03T11:40:02.112614Z ERROR bevy_log: Could not set global logger as it is already set. Consider disabling LogPlugin.
2025-09-03T11:40:02.112632Z ERROR bevy_log: Could not set global tracing subscriber as it is already set. Consider disabling LogPlugin.
2025-09-03T11:40:02.114802Z INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux (Garuda Linux Soaring)", kernel: "6.16.3-zen1-1-zen", cpu: "12th Gen Intel(R) Core(TM) i9-12900HK", core_count: "14", memory: "31.0 GiB" }
2025-09-03T11:40:02.115040Z INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux (Garuda Linux Soaring)", kernel: "6.16.3-zen1-1-zen", cpu: "12th Gen Intel(R) Core(TM) i9-12900HK", core_count: "14", memory: "31.0 GiB" }
2025-09-03T11:40:02.116709Z INFO bevy_app::terminal_ctrl_c_handler: Skipping installing `Ctrl+C` handler as one was already installed. Please call `TerminalCtrlCHandlerPlugin::gracefully_exit` in your own `Ctrl+C` handler if you want Bevy to gracefully exit on `Ctrl+C`.
test test_defaults_but_null_renderer ... FAILED
2025-09-03T11:40:02.154035Z ERROR bevy_render::extract_resource: Render app did not exist when trying to add `extract_resource` for <bevy_render::camera::manual_texture_view::ManualTextureViews>.
2025-09-03T11:40:02.457347Z WARN bevy_gizmos: bevy_render feature is enabled but RenderApp was not detected. Are you sure you loaded GizmoPlugin after RenderPlugin?
test run_test_again ... ok
failures:
---- test_defaults_but_null_renderer stdout ----
thread 'test_defaults_but_null_renderer' panicked at /home/fella/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_winit-0.16.1/src/lib.rs:125:14:
Failed to build event loop: RecreationAttempt
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
test_defaults_but_null_renderer
test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.38s However nextest can work around it: it runs tests in parallel processes. nextest$ cargo nextest run
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.12s
────────────
Nextest run ID 636d7d92-d159-4600-84a2-607982ad7bc5 with nextest profile: default
Starting 2 tests across 1 binary
PASS [ 0.382s] test3d::bin/test3d run_test_again
PASS [ 0.395s] test3d::bin/test3d test_defaults_but_null_renderer
────────────
Summary [ 0.395s] 2 tests run: 2 passed, 0 skipped |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I'm trying to make tests for systems and can't figure out how to make tests for system that are aware of Mesh3d components.
bevy examples shows only using #[test] for systems that use their only components or input or tests that are not #tests at all
How to test systems which are operate on mesh3d? Here are several attempts I tried with zero success:
(The task itself is simple: reach
assert_eq!(0, 2, "might as well be unreachable!()");
after a mesh was created. Since it's a#[test]
the real window must not be created and we want to useapp.update
instead of multiframe.run
)Firstly, running all tests at the same time is no-no:
pain
It's not like running them separately helps:
pain of cargo test -- --nocapture test_defaults_as_if_testing_was_sane
Then let's try to use what winit offers
pain of cargo test -- --nocapture 'test_defaults_but_looking_at_winit_angrily'
Then let's try minimal as test in repo uses
cargo test -- --nocapture 'test_minimal_as_if_testing_was_sane'
And I then I tried manually to add plugins until bevy stops complaining.
cargo test -- --nocapture 'test_minimal_but_trying_to_load_plugins'
Then decided different order
trying in different order looks promising, but still unclear
So. Is there a template for making a #[test]s that are able to test systems that spawn a mesh?
Beta Was this translation helpful? Give feedback.
All reactions