bevyengine / bevyengine/bevy

Add convenience methods for integration testing the ECS

Open
#3,814 1 comment 0 reactions 0 assignees View on GitHub
A-ECS C-Usability
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

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

Integration testing is important, but our existing tools for it are boilerplate-heavy.

## What solution would you like?

There are a few patterns that come up very regularly, and should be supported directly on the `App` and `World`:

- assert that the resource of the given type matches the provided value
- assert that all components that match a query match the given tuple of values
- assert that the number of entities returned by a query is `n`

Each method on `App` should just call the underlying method on `World`.

## What alternative(s) have you considered?

These helper methods can be written entirely externally. However, this is suboptimal because:
- friction is one of the largest barriers to testing
- this code is going to be exactly the same across all serious products created with Bevy
- Bevy itself should be integration tested, and would benefit from these ergonomics improvements

## Additional context

This pattern is very useful when combined with manually calling `app.update()` in your integration tests.

#3786 would make organizing these sorts of ergonomics methods more convenient.

I've also written a number of [tools for input-mocking](https://github.com/Leafwing-Studios/leafwing-input-manager/blob/main/src/input_mocking.rs) that are very useful, but those should be considered in a separate issue / PR.

Contributor guide

Open the contributing guide

Research direction

Start by locating the App and World entry points and existing ECS integration tests, then review how resources and query results are currently inspected. Done means App exposes forwarding helpers for World, while World supports resource-value, matching-component, and entity-count assertions for integration tests using app.update().

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.