Skip to content

Add better scene tests #6834

@MrGVSV

Description

@MrGVSV

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

When 0.9 was initially released, there were some scene-related bugs that went unnoticed. These included:

Unfortunately, these were not rare edge cases that slipped through. These were just the result of people using the new scene format in actual projects.

The reason we didn't catch these bugs right away is that our current tests don't relate to real-world scenarios— or at least not a decent handful of them.

What solution would you like?

In the tests folder in the root of the project, we should include some tests for scenes. These tests should generally:

  1. Contain moderately complex structures (deep hierarchies, Vec/HashMap usage, etc.)
  2. Use a fair amount of Bevy built-in components
  3. Use differently "shaped" components (tuple structs, unit structs, enums, etc.)

Additionally, they should all ensure that we can:

  1. Serialize to a string/file
  2. Deserialize from a string/file

While we do want to have really complex scenes, we should also try to break things up so we can isolate particular areas of interest. So here are some of the test files I think we should have:

  • scenes/relations.rs - Focus on hierarchies and basic relations (e.g. struct Pet(Entity)).
  • scenes/ui.rs - Focus on (de)serializing UI (if possible).
  • scenes/components.rs - Focus on components of all shapes and sizes— both from Bevy and custom-made.

These are not a requirement and there may be more tests (or fewer) that we want to add. The basic idea is to at least have enough that we can be confident changes to the scene format or other code won't be immediately broken at the next release.

What alternative(s) have you considered?

There are a couple alternatives we could try:

  1. Create new examples
  2. Add to the crate-level tests

The reason why I don't think we should go with the first one is that these really need to be more like tests: slightly more complex, checking edge cases, doing multiple things, etc. I don't think examples are really meant for that and wouldn't really benefit those reading through it.

And the reason I don't think we should go with the second is that we're not really using the same API as users. Not only might there be differences in how the API is used, but we might be missing some types/components that we can't pull in without adding them as a dependency. We could maybe do it, but I think just handling it in the tests directory is going to be much simpler/more accurate.

Additional context

Reference comment: #6580 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ScenesSerialized ECS data stored on the diskC-TestingA change that impacts how we test Bevy or how users test their apps

    Type

    No type

    Projects

    Status

    Open

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions