-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Show basic application integration testing (#2896) #7314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -0,0 +1,113 @@ | |||
use bevy::prelude::*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Module level docs please :) Laying out a bit of an intro of "this is what we're testing and why" is really helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
tests/how_to_test_full_app.rs
Outdated
app | ||
} | ||
|
||
fn add_game_systems(app: &mut App) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use a plugin: it's extremely useful to refactor your game such that some plugins can be added directly to the test setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I have changed it into a plugin.
Great to see this; this is something I've been asked about a lot. |
7c25528
to
d27ee17
Compare
…dule level documentation.
a0b7390
to
00c9492
Compare
Apologies for replacing the commit twice. Turns out if you do the |
tests/how_to_test_full_app.rs
Outdated
@@ -0,0 +1,132 @@ | |||
//! This module serves as an example, and test-case, for how to automatically test full bevy apps. | |||
//! | |||
//! The way it works, is by substituting the [`DefaultPlugins`] with [`MinimalPlugins`], which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//! The way it works, is by substituting the [`DefaultPlugins`] with [`MinimalPlugins`], which | |
By substituting [`DefaultPlugins`] with [`MinimalPlugins`], Bevy can run completely headless. | |
Then, the app can be advanced one tick at a time with [`App::update`]. |
tests/how_to_test_full_app.rs
Outdated
//! This module serves as an example, and test-case, for how to automatically test full bevy apps. | ||
//! | ||
//! The way it works, is by substituting the [`DefaultPlugins`] with [`MinimalPlugins`], which | ||
//! allows bevy to run completely headless. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//! allows bevy to run completely headless. |
tests/how_to_test_full_app.rs
Outdated
//! | ||
//! The list of minimal plugins does not include things like window or input handling. | ||
//! This has as downside that the resources / entities associated with those systems | ||
//! (for example: `Input::<KeyCode>`) need to be manually added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//! (for example: `Input::<KeyCode>`) need to be manually added. | |
//! (for example: `Input::<KeyCode>`) need to be manually added, either directly or via e.g. [`InputPlugin`]. |
tests/how_to_test_full_app.rs
Outdated
//! The upside however, is that the test has complete control over these resources, meaning | ||
//! we can fake user input, fake the window being moved around, and more. | ||
//! | ||
//! The benefit of having this set of example tests be run by the CI system, is that we ensure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove these sentences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some feedback on the module level docs for you :) I like them, but we can tighten them up. And much better with a GamePlugin
!
# Objective This older PR from `Wcubed` seemed well worth saving, adopted from #7314. See also tracking issue #2896 for ongoing discussion of Bevy testability. Thanks `Wcubed`! ## Solution - Updated for 0.15 - Added the `expected`/`actual` pattern - Switched to function plugin - Tweaked a bit of description ## Testing Green. --------- Co-authored-by: Wybe Westra <[email protected]> Co-authored-by: Wybe Westra <[email protected]>
# Objective This older PR from `Wcubed` seemed well worth saving, adopted from bevyengine#7314. See also tracking issue bevyengine#2896 for ongoing discussion of Bevy testability. Thanks `Wcubed`! ## Solution - Updated for 0.15 - Added the `expected`/`actual` pattern - Switched to function plugin - Tweaked a bit of description ## Testing Green. --------- Co-authored-by: Wybe Westra <[email protected]> Co-authored-by: Wybe Westra <[email protected]>
# Objective This older PR from `Wcubed` seemed well worth saving, adopted from bevyengine#7314. See also tracking issue bevyengine#2896 for ongoing discussion of Bevy testability. Thanks `Wcubed`! ## Solution - Updated for 0.15 - Added the `expected`/`actual` pattern - Switched to function plugin - Tweaked a bit of description ## Testing Green. --------- Co-authored-by: Wybe Westra <[email protected]> Co-authored-by: Wybe Westra <[email protected]>
Objective
Show an example of how the integration testing of a bevy application can be structured, for #2896.
I went for basic window interaction and user input for the examples, but there are certainly other areas that would be good to demonstrate, I just haven't worked with the engine enough to point them out. Suggestions are welcome :)