Skip to content

Provide a way to test Bevy App #2896

@arialpew

Description

@arialpew

What problem does this solve or what need does it fill?

Bevy App should be testable in headless mode (no renderer), for Continuous Integration and fast feedback when user logic / system interaction is not what user intendeed.

What solution would you like?

Idealy, a complete example for testing a Bevy App should be provided out of the box.

Currently, there's a minimal example provided here : https://github.com/bevyengine/bevy/blob/main/crates/bevy_ecs/examples/resources.rs

This doesn't work well because you have no way to test things that happen "later in time". You advance Bevy synchronously with iteration in a for loop. If you sleep the main thread between each iteration, you'll advance in time but the side effect is test will be slower. So this example work well for startup system or system that run each tick, but this doesn't work for system that happen "later" in time.

We need a way to test a Bevy Application and travel time to a future point where Bevy State is updated, so assertion can work, for all case (FixedTimeStep System or not).

  1. Provide a way to advance or scale Bevy time, skip frame, for test (custom Scheduler ? Or maybe the current default Scheduler is enough ?).
  2. Test should be runnable concurrently with cargo test, some plugins are not compatible (for example, LogPlugin is not usable in context of a test if 2 Bevy App use 2 instance of LogPlugin concurrently).
  3. Documentation.

What alternative(s) have you considered?

Don't bother with testing, stay like this.

Honestly, for small Bevy App you don't need test, but for complex system interaction it's a nice feature.

I'm confident about Bevy behavior and logic, but I don't trust my own code especially when it's inverted control (https://en.wikipedia.org/wiki/Inversion_of_control, the framework is responsible to run my application).

A nice side effect of this feature is if you make Bevy easily testable (out of the box with cargo test), contributors will have a better understanding of Bevy code base/change.

Additional context

Related : #1057 and #1720 and #2687

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AppBevy apps and pluginsC-ExamplesAn addition or correction to our examplesC-TestingA change that impacts how we test Bevy or how users test their appsS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions