Skip to content

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

Closed
wants to merge 4 commits into from

Conversation

Wcubed
Copy link
Contributor

@Wcubed Wcubed commented Jan 21, 2023

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 :)

@alice-i-cecile alice-i-cecile added C-Examples An addition or correction to our examples C-Testing A change that impacts how we test Bevy or how users test their apps labels Jan 21, 2023
@@ -0,0 +1,113 @@
use bevy::prelude::*;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

app
}

fn add_game_systems(app: &mut App) {
Copy link
Member

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.

Copy link
Contributor Author

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.

@alice-i-cecile
Copy link
Member

Great to see this; this is something I've been asked about a lot.

@Wcubed Wcubed force-pushed the integration-test-examples branch from 7c25528 to d27ee17 Compare January 21, 2023 20:31
@Wcubed Wcubed force-pushed the integration-test-examples branch from a0b7390 to 00c9492 Compare January 21, 2023 22:20
@Wcubed
Copy link
Contributor Author

Wcubed commented Jan 21, 2023

Apologies for replacing the commit twice. Turns out if you do the cargo run -p ci on nightly, it will come up with more lints than when it is run on stable, so on my pc it always failed instead of showing what the ci on github would say about the code. Which made it a bit difficult to pre-empt the remarks of the ci 😄 .

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! 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`].

//! 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! allows bevy to run completely headless.

//!
//! 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! (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`].

//! 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
Copy link
Member

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.

Copy link
Member

@alice-i-cecile alice-i-cecile left a 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!

@bas-ie
Copy link
Contributor

bas-ie commented Nov 23, 2024

Seems a shame to lose this: adopted in #16489. Thanks @Wcubed!

@bas-ie bas-ie closed this Nov 23, 2024
github-merge-queue bot pushed a commit that referenced this pull request Nov 24, 2024
# 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]>
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Dec 2, 2024
# 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]>
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Jan 6, 2025
# 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Examples An addition or correction to our examples C-Testing A change that impacts how we test Bevy or how users test their apps
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants