Skip to content
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

Allow bevy to be run as an integration test inside a #[test] #1057

Closed
refnil opened this issue Dec 13, 2020 · 3 comments
Closed

Allow bevy to be run as an integration test inside a #[test] #1057

refnil opened this issue Dec 13, 2020 · 3 comments
Labels
A-Build-System Related to build systems or continuous integration A-Core Common functionality for all bevy apps C-Feature A new feature, making something new possible

Comments

@refnil
Copy link
Contributor

refnil commented Dec 13, 2020

What problem does this solve or what need does it fill?
Make game/project made with bevy as easily testable as possible. It would also help bevy proper since more integration test could be added.

Describe the solution would you like?
I would like to be able to run a bevy app from a #[test] function. In particular, I think it is important to be able to run windowed app.

Describe the alternative(s) you've considered?

  • If you only want to check if the code compile, examples could be used. However, that is not really a full testing framework.
  • Make a #[bevy::test] attribute that do a bit of the repetitive work of bevy test. Some kind of recommended way of doing thing. I think it is a good idea for the future.

Additional context
I have a working prototype that work for running test on linux with x11. First, let me explain the four problems that I had to solve to make it work.

  • Panicking in a bevy app create a nested panic which abort the current process. That prevent the test to continue after the first fail.
  • The event_loop used in bevy_init can only be created on the main thread but tests are not run on that thread.
  • If you run multiple windowed bevy app simultaneously, window events won't go to the right event loop. That cause a panic when receiving a window events for a window that bevy doesn't know about.
  • If you run multiple windowed bevy app sequentially, you can still receive old event that are destined for the previous test.

I intend to make multiple pull request to fix these problems in the coming days. You can check my WIP on https://github.com/refnil/bevy/commits/master.

Two quick questions that would help me make better pull requests?

  • Could you force the event loop to drain outside of a bevy app?
  • Is it intended/a good practice to panic! in a panic! in the task_pool Drop implementation?

Two inspirations for this issues:

  • UnityTest attribute: Create an empty scene to run a test. It could also be a good idea when scene and system loading and unloading is ironed out. Loading a complete bevy app is more general anyway and could fit more purpose.
  • Factorio integration testing video: Looks real nice and I want that for bevy haha.

Happy to ear what you think about this.
Thanks for your cool project.

@refnil refnil changed the title Allow bevy to be run as a integration test inside a #[test] Allow bevy to be run as an integration test inside a #[test] Dec 13, 2020
@Moxinilian Moxinilian added A-Build-System Related to build systems or continuous integration A-Core Common functionality for all bevy apps C-Feature A new feature, making something new possible labels Dec 15, 2020
@cart
Copy link
Member

cart commented Dec 22, 2020

Diving into this now. I've started trying to unit test "full" Bevy apps and your changes appear to do the trick. Thanks!

@alice-i-cecile
Copy link
Member

This is now resolved for apps that do not require graphics. See this real-life example.

Once #3754 is solved I think this can be closed.

@alice-i-cecile
Copy link
Member

Closing now as redundant to #3754 and #2896.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Build-System Related to build systems or continuous integration A-Core Common functionality for all bevy apps C-Feature A new feature, making something new possible
Projects
None yet
Development

No branches or pull requests

4 participants